
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Garbage Collector Controller 源码分析 · 这是程序员吗</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="xishengcai">
        
        
    
    
    <link rel="stylesheet" href="../../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-toggle-chapters/toggle.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-search-plus/search.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-disqus/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-prism/prism-base16-ateliersulphurpool.light.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-advanced-emoji/emoji-website.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-anchors/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-emphasize/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-katex/katex.min.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.css">
                
            
                
                <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-sectionx/sectionx.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-donate/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-local-video/video-js.min.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-terminal/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-alerts/style.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-versions-select/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-theme-comscore/test.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    


    

        
    
    
    
    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="job.html" />
    
    
    <link rel="prev" href="calico 源码分析.html" />
    

    
    <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-chart/c3/c3.min.css">
    <script src="../../../gitbook/gitbook-plugin-chart/c3/d3.min.js"></script>
    <script src="../../../gitbook/gitbook-plugin-chart/c3/c3.min.js"></script>
    

    <script src="../../../gitbook/gitbook-plugin-graph/d3.min.js"></script>
    <script src="../../../gitbook/gitbook-plugin-graph/function-plot.js"></script>    

    
        <link rel="shortcut icon" href='../../../favicon.ico' type="image/x-icon">
    
    
        <link rel="bookmark" href='../../../favicon.ico' type="image/x-icon">
    
    
    

    <style>
    @media only screen and (max-width: 640px) {
        .book-header .hidden-mobile {
            display: none;
        }
    }
    </style>
    <script>
        window["gitbook-plugin-github-buttons"] = {"repo":"xishengcai/xisheng.blog","types":["star"],"size":"small"};
    </script>

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="https://xisheng.vip" target="_blank" class="custom-link">Home</a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        <li class="header">Blog</li>
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../../">
            
                <a href="../../../">
            
                    
                        <b>1.1.</b>
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../../algorithm/">
            
                <a href="../../algorithm/">
            
                    
                        <b>1.2.</b>
                    
                    Algorithm
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../../algorithm/heap.html">
            
                <a href="../../algorithm/heap.html">
            
                    
                        <b>1.2.1.</b>
                    
                    Heap
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../../algorithm/readme.html">
            
                <a href="../../algorithm/readme.html">
            
                    
                        <b>1.2.2.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../../angular/">
            
                <a href="../../angular/">
            
                    
                        <b>1.3.</b>
                    
                    Angular
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../../angular/1-start.html">
            
                <a href="../../angular/1-start.html">
            
                    
                        <b>1.3.1.</b>
                    
                    Start
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../../angular/2-component.html">
            
                <a href="../../angular/2-component.html">
            
                    
                        <b>1.3.2.</b>
                    
                    Component
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../../angular/3-form.html">
            
                <a href="../../angular/3-form.html">
            
                    
                        <b>1.3.3.</b>
                    
                    Form
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../../angular/readme.html">
            
                <a href="../../angular/readme.html">
            
                    
                        <b>1.3.4.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../../database/">
            
                <a href="../../database/">
            
                    
                        <b>1.4.</b>
                    
                    Database
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../../database/mongodb.html">
            
                <a href="../../database/mongodb.html">
            
                    
                        <b>1.4.1.</b>
                    
                    Mongodb
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../../database/readme.html">
            
                <a href="../../database/readme.html">
            
                    
                        <b>1.4.2.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../../docker/">
            
                <a href="../../docker/">
            
                    
                        <b>1.5.</b>
                    
                    Docker
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../../docker/CentOS.html">
            
                <a href="../../docker/CentOS.html">
            
                    
                        <b>1.5.1.</b>
                    
                    CentOS
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../../docker/install.html">
            
                <a href="../../docker/install.html">
            
                    
                        <b>1.5.2.</b>
                    
                    Install
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../../docker/readme.html">
            
                <a href="../../docker/readme.html">
            
                    
                        <b>1.5.3.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../../docker/官方shell.html">
            
                <a href="../../docker/官方shell.html">
            
                    
                        <b>1.5.4.</b>
                    
                    官方Shell
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../../golang/">
            
                <a href="../../golang/">
            
                    
                        <b>1.6.</b>
                    
                    Golang
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../../golang/aop.html">
            
                <a href="../../golang/aop.html">
            
                    
                        <b>1.6.1.</b>
                    
                    Aop
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../../golang/base/">
            
                <a href="../../golang/base/">
            
                    
                        <b>1.6.2.</b>
                    
                    Base
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.2.1" data-path="../../golang/base/copy.html">
            
                <a href="../../golang/base/copy.html">
            
                    
                        <b>1.6.2.1.</b>
                    
                    Copy
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2.2" data-path="../../golang/base/new_and_make.html">
            
                <a href="../../golang/base/new_and_make.html">
            
                    
                        <b>1.6.2.2.</b>
                    
                    New And Make
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2.3" data-path="../../golang/base/readme.html">
            
                <a href="../../golang/base/readme.html">
            
                    
                        <b>1.6.2.3.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2.4" data-path="../../golang/base/reflect.html">
            
                <a href="../../golang/base/reflect.html">
            
                    
                        <b>1.6.2.4.</b>
                    
                    Reflect
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2.5" data-path="../../golang/base/string.html">
            
                <a href="../../golang/base/string.html">
            
                    
                        <b>1.6.2.5.</b>
                    
                    String
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2.6" data-path="../../golang/base/tag.html">
            
                <a href="../../golang/base/tag.html">
            
                    
                        <b>1.6.2.6.</b>
                    
                    Tag
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../../golang/clouser.html">
            
                <a href="../../golang/clouser.html">
            
                    
                        <b>1.6.3.</b>
                    
                    Clouser
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../../golang/err 优雅处理.html">
            
                <a href="../../golang/err 优雅处理.html">
            
                    
                        <b>1.6.4.</b>
                    
                    Err 优雅处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="../../golang/go module 2.html">
            
                <a href="../../golang/go module 2.html">
            
                    
                        <b>1.6.5.</b>
                    
                    Go Module 2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="../../golang/go_mod.html">
            
                <a href="../../golang/go_mod.html">
            
                    
                        <b>1.6.6.</b>
                    
                    Go Mod
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" data-path="../../golang/gocraftwork.html">
            
                <a href="../../golang/gocraftwork.html">
            
                    
                        <b>1.6.7.</b>
                    
                    Gocraftwork
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.8" data-path="../../golang/oauth.html">
            
                <a href="../../golang/oauth.html">
            
                    
                        <b>1.6.8.</b>
                    
                    Oauth
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.9" data-path="../../golang/readme.html">
            
                <a href="../../golang/readme.html">
            
                    
                        <b>1.6.9.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.10" data-path="../../golang/swagger.html">
            
                <a href="../../golang/swagger.html">
            
                    
                        <b>1.6.10.</b>
                    
                    Swagger
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.11" data-path="../../golang/tls.html">
            
                <a href="../../golang/tls.html">
            
                    
                        <b>1.6.11.</b>
                    
                    Tls
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.12" >
            
                <span>
            
                    
                        <b>1.6.12.</b>
                    
                    代码走读
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.12.1" data-path="../../golang/代码走读/2020.5.26.html">
            
                <a href="../../golang/代码走读/2020.5.26.html">
            
                    
                        <b>1.6.12.1.</b>
                    
                    2020.5.26
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6.13" data-path="../../golang/任务队列/">
            
                <a href="../../golang/任务队列/">
            
                    
                        <b>1.6.13.</b>
                    
                    任务队列
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.13.1" data-path="../../golang/任务队列/gocraft-worker.html">
            
                <a href="../../golang/任务队列/gocraft-worker.html">
            
                    
                        <b>1.6.13.1.</b>
                    
                    Gocraft Worker
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.13.2" data-path="../../golang/任务队列/readme.html">
            
                <a href="../../golang/任务队列/readme.html">
            
                    
                        <b>1.6.13.2.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6.14" data-path="../../golang/参数校验.html">
            
                <a href="../../golang/参数校验.html">
            
                    
                        <b>1.6.14.</b>
                    
                    参数校验
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../../istio/">
            
                <a href="../../istio/">
            
                    
                        <b>1.7.</b>
                    
                    Istio
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../../istio/readme.html">
            
                <a href="../../istio/readme.html">
            
                    
                        <b>1.7.1.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../../istio/virtualservice.html">
            
                <a href="../../istio/virtualservice.html">
            
                    
                        <b>1.7.2.</b>
                    
                    Virtualservice
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" >
            
                <span>
            
                    
                        <b>1.8.</b>
                    
                    Java
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../../java/jvm.html">
            
                <a href="../../java/jvm.html">
            
                    
                        <b>1.8.1.</b>
                    
                    Jvm
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../../java/typescript.html">
            
                <a href="../../java/typescript.html">
            
                    
                        <b>1.8.2.</b>
                    
                    Typescript
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../">
            
                <a href="../">
            
                    
                        <b>1.9.</b>
                    
                    Kubernetes
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="../APIService.html">
            
                <a href="../APIService.html">
            
                    
                        <b>1.9.1.</b>
                    
                    APIService
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="../CAK.html">
            
                <a href="../CAK.html">
            
                    
                        <b>1.9.2.</b>
                    
                    CAK
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.3" data-path="../Deployment 的实现原理.html">
            
                <a href="../Deployment 的实现原理.html">
            
                    
                        <b>1.9.3.</b>
                    
                    Deployment 的实现原理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4" data-path="./">
            
                <a href="./">
            
                    
                        <b>1.9.4.</b>
                    
                    K8s源码
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.4.1" data-path="calico 源码分析.html">
            
                <a href="calico 源码分析.html">
            
                    
                        <b>1.9.4.1.</b>
                    
                    Calico 源码分析
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.9.4.2" data-path="garbage collector controller 源码分析.html">
            
                <a href="garbage collector controller 源码分析.html">
            
                    
                        <b>1.9.4.2.</b>
                    
                    Garbage Collector Controller 源码分析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4.3" data-path="job.html">
            
                <a href="job.html">
            
                    
                        <b>1.9.4.3.</b>
                    
                    Job
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4.4" data-path="kube-proxy-iptables.html">
            
                <a href="kube-proxy-iptables.html">
            
                    
                        <b>1.9.4.4.</b>
                    
                    Kube Proxy Iptables
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4.5" data-path="kube-proxy-ipvs.html">
            
                <a href="kube-proxy-ipvs.html">
            
                    
                        <b>1.9.4.5.</b>
                    
                    Kube Proxy Ipvs
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4.6" data-path="kube-proxy.html">
            
                <a href="kube-proxy.html">
            
                    
                        <b>1.9.4.6.</b>
                    
                    Kube Proxy
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4.7" data-path="kubectl-exec.html">
            
                <a href="kubectl-exec.html">
            
                    
                        <b>1.9.4.7.</b>
                    
                    Kubectl Exec
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4.8" data-path="kubectl源码阅读1.html">
            
                <a href="kubectl源码阅读1.html">
            
                    
                        <b>1.9.4.8.</b>
                    
                    Kubectl源码阅读1
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4.9" data-path="kubectl源码阅读2.html">
            
                <a href="kubectl源码阅读2.html">
            
                    
                        <b>1.9.4.9.</b>
                    
                    Kubectl源码阅读2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4.10" data-path="readme.html">
            
                <a href="readme.html">
            
                    
                        <b>1.9.4.10.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4.11" data-path="schedule.html">
            
                <a href="schedule.html">
            
                    
                        <b>1.9.4.11.</b>
                    
                    Schedule
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4.12" data-path="scheme.html">
            
                <a href="scheme.html">
            
                    
                        <b>1.9.4.12.</b>
                    
                    Scheme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4.13" data-path="调度队列.html">
            
                <a href="调度队列.html">
            
                    
                        <b>1.9.4.13.</b>
                    
                    调度队列
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9.5" data-path="../Karmada.html">
            
                <a href="../Karmada.html">
            
                    
                        <b>1.9.5.</b>
                    
                    Karmada
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.6" data-path="../Pixie.html">
            
                <a href="../Pixie.html">
            
                    
                        <b>1.9.6.</b>
                    
                    Pixie
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.7" data-path="../admission access.html">
            
                <a href="../admission access.html">
            
                    
                        <b>1.9.7.</b>
                    
                    Admission Access
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.8" data-path="../ccm.html">
            
                <a href="../ccm.html">
            
                    
                        <b>1.9.8.</b>
                    
                    Ccm
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.9" data-path="../client-go.html">
            
                <a href="../client-go.html">
            
                    
                        <b>1.9.9.</b>
                    
                    Client Go
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.10" data-path="../command.html">
            
                <a href="../command.html">
            
                    
                        <b>1.9.10.</b>
                    
                    Command
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.11" data-path="../controller.html">
            
                <a href="../controller.html">
            
                    
                        <b>1.9.11.</b>
                    
                    Controller
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.12" data-path="../copy docker config.html">
            
                <a href="../copy docker config.html">
            
                    
                        <b>1.9.12.</b>
                    
                    Copy Docker Config
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.13" data-path="../etcd-operation.html">
            
                <a href="../etcd-operation.html">
            
                    
                        <b>1.9.13.</b>
                    
                    Etcd Operation
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.14" data-path="../gc.html">
            
                <a href="../gc.html">
            
                    
                        <b>1.9.14.</b>
                    
                    Gc
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.15" data-path="../helm chart.html">
            
                <a href="../helm chart.html">
            
                    
                        <b>1.9.15.</b>
                    
                    Helm Chart
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.16" data-path="../helm.html">
            
                <a href="../helm.html">
            
                    
                        <b>1.9.16.</b>
                    
                    Helm
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.17" >
            
                <span>
            
                    
                        <b>1.9.17.</b>
                    
                    Helm
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.17.1" data-path="../helm/charts.html">
            
                <a href="../helm/charts.html">
            
                    
                        <b>1.9.17.1.</b>
                    
                    Charts
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.17.2" data-path="../helm/helm 钩子函数.html">
            
                <a href="../helm/helm 钩子函数.html">
            
                    
                        <b>1.9.17.2.</b>
                    
                    Helm 钩子函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.17.3" data-path="../helm/helm-operator.html">
            
                <a href="../helm/helm-operator.html">
            
                    
                        <b>1.9.17.3.</b>
                    
                    Helm Operator
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.17.4" data-path="../helm/文档查询.html">
            
                <a href="../helm/文档查询.html">
            
                    
                        <b>1.9.17.4.</b>
                    
                    文档查询
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.17.5" data-path="../helm/语法.html">
            
                <a href="../helm/语法.html">
            
                    
                        <b>1.9.17.5.</b>
                    
                    语法
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9.18" data-path="../install.html">
            
                <a href="../install.html">
            
                    
                        <b>1.9.18.</b>
                    
                    Install
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.19" data-path="../istio-inject.html">
            
                <a href="../istio-inject.html">
            
                    
                        <b>1.9.19.</b>
                    
                    Istio Inject
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.20" >
            
                <span>
            
                    
                        <b>1.9.20.</b>
                    
                    KubeEdge
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.21" data-path="../kuber-apiserver-flag.html">
            
                <a href="../kuber-apiserver-flag.html">
            
                    
                        <b>1.9.21.</b>
                    
                    Kuber Apiserver Flag
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.22" data-path="../kubernetes-client.html">
            
                <a href="../kubernetes-client.html">
            
                    
                        <b>1.9.22.</b>
                    
                    Kubernetes Client
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.23" data-path="../kubernetes灾备.html">
            
                <a href="../kubernetes灾备.html">
            
                    
                        <b>1.9.23.</b>
                    
                    Kubernetes灾备
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.24" data-path="../kubesphere/">
            
                <a href="../kubesphere/">
            
                    
                        <b>1.9.24.</b>
                    
                    Kubesphere
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.24.1" data-path="../kubesphere/helm.html">
            
                <a href="../kubesphere/helm.html">
            
                    
                        <b>1.9.24.1.</b>
                    
                    Helm
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.24.2" data-path="../kubesphere/readme.html">
            
                <a href="../kubesphere/readme.html">
            
                    
                        <b>1.9.24.2.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9.25" data-path="../kubevela/">
            
                <a href="../kubevela/">
            
                    
                        <b>1.9.25.</b>
                    
                    Kubevela
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.25.1" data-path="../kubevela/KubeVela 功能.html">
            
                <a href="../kubevela/KubeVela 功能.html">
            
                    
                        <b>1.9.25.1.</b>
                    
                    KubeVela 功能
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.25.2" data-path="../kubevela/cue.html">
            
                <a href="../kubevela/cue.html">
            
                    
                        <b>1.9.25.2.</b>
                    
                    Cue
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.25.3" data-path="../kubevela/oam.html">
            
                <a href="../kubevela/oam.html">
            
                    
                        <b>1.9.25.3.</b>
                    
                    Oam
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.25.4" data-path="../kubevela/readme.html">
            
                <a href="../kubevela/readme.html">
            
                    
                        <b>1.9.25.4.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.25.5" data-path="../kubevela/rollout design.html">
            
                <a href="../kubevela/rollout design.html">
            
                    
                        <b>1.9.25.5.</b>
                    
                    Rollout Design
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.25.6" data-path="../kubevela/vela run.html">
            
                <a href="../kubevela/vela run.html">
            
                    
                        <b>1.9.25.6.</b>
                    
                    Vela Run
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.25.7" data-path="../kubevela/vela up.html">
            
                <a href="../kubevela/vela up.html">
            
                    
                        <b>1.9.25.7.</b>
                    
                    Vela Up
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.25.8" data-path="../kubevela/vela-cluster.html">
            
                <a href="../kubevela/vela-cluster.html">
            
                    
                        <b>1.9.25.8.</b>
                    
                    Vela Cluster
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.25.9" data-path="../kubevela/vela-helm.html">
            
                <a href="../kubevela/vela-helm.html">
            
                    
                        <b>1.9.25.9.</b>
                    
                    Vela Helm
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.25.10" data-path="../kubevela/vela-pk-oam.html">
            
                <a href="../kubevela/vela-pk-oam.html">
            
                    
                        <b>1.9.25.10.</b>
                    
                    Vela Pk Oam
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9.26" data-path="../mk-cert.html">
            
                <a href="../mk-cert.html">
            
                    
                        <b>1.9.26.</b>
                    
                    Mk Cert
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.27" data-path="../open_swagger-ui.html">
            
                <a href="../open_swagger-ui.html">
            
                    
                        <b>1.9.27.</b>
                    
                    Open Swagger Ui
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.28" data-path="../readme.html">
            
                <a href="../readme.html">
            
                    
                        <b>1.9.28.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.29" data-path="../task/">
            
                <a href="../task/">
            
                    
                        <b>1.9.29.</b>
                    
                    Task
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.29.1" data-path="../task/HPA.html">
            
                <a href="../task/HPA.html">
            
                    
                        <b>1.9.29.1.</b>
                    
                    HPA
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.29.2" data-path="../task/kubectl patch.html">
            
                <a href="../task/kubectl patch.html">
            
                    
                        <b>1.9.29.2.</b>
                    
                    Kubectl Patch
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.29.3" data-path="../task/pod 信息注入.html">
            
                <a href="../task/pod 信息注入.html">
            
                    
                        <b>1.9.29.3.</b>
                    
                    Pod 信息注入
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.29.4" data-path="../task/pod 垂直扩缩容.html">
            
                <a href="../task/pod 垂直扩缩容.html">
            
                    
                        <b>1.9.29.4.</b>
                    
                    Pod 垂直扩缩容
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.29.5" data-path="../task/readme.html">
            
                <a href="../task/readme.html">
            
                    
                        <b>1.9.29.5.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.29.6" data-path="../task/server-side-apply.html">
            
                <a href="../task/server-side-apply.html">
            
                    
                        <b>1.9.29.6.</b>
                    
                    Server Side Apply
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.29.7" data-path="../task/准入控制.html">
            
                <a href="../task/准入控制.html">
            
                    
                        <b>1.9.29.7.</b>
                    
                    准入控制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.29.8" data-path="../task/聚合api.html">
            
                <a href="../task/聚合api.html">
            
                    
                        <b>1.9.29.8.</b>
                    
                    聚合Api
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.29.9" data-path="../task/资源预留配置.html">
            
                <a href="../task/资源预留配置.html">
            
                    
                        <b>1.9.29.9.</b>
                    
                    资源预留配置
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9.30" data-path="../webhook.html">
            
                <a href="../webhook.html">
            
                    
                        <b>1.9.30.</b>
                    
                    Webhook
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.31" data-path="../一致性认证.html">
            
                <a href="../一致性认证.html">
            
                    
                        <b>1.9.31.</b>
                    
                    一致性认证
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.32" data-path="../专利名词.html">
            
                <a href="../专利名词.html">
            
                    
                        <b>1.9.32.</b>
                    
                    专利名词
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.33" data-path="../删除namespace.html">
            
                <a href="../删除namespace.html">
            
                    
                        <b>1.9.33.</b>
                    
                    删除Namespace
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.34" data-path="../简化多集群.html">
            
                <a href="../简化多集群.html">
            
                    
                        <b>1.9.34.</b>
                    
                    简化多集群
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.35" data-path="../网络插件/">
            
                <a href="../网络插件/">
            
                    
                        <b>1.9.35.</b>
                    
                    网络插件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.35.1" data-path="../网络插件/calico.html">
            
                <a href="../网络插件/calico.html">
            
                    
                        <b>1.9.35.1.</b>
                    
                    Calico
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.35.2" data-path="../网络插件/cilium.html">
            
                <a href="../网络插件/cilium.html">
            
                    
                        <b>1.9.35.2.</b>
                    
                    Cilium
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.35.3" data-path="../网络插件/ebpf.html">
            
                <a href="../网络插件/ebpf.html">
            
                    
                        <b>1.9.35.3.</b>
                    
                    Ebpf
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.35.4" data-path="../网络插件/readme.html">
            
                <a href="../网络插件/readme.html">
            
                    
                        <b>1.9.35.4.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9.36" data-path="../镜像/">
            
                <a href="../镜像/">
            
                    
                        <b>1.9.36.</b>
                    
                    镜像
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.36.1" data-path="../镜像/Containerd Stargz Snapshotter.html">
            
                <a href="../镜像/Containerd Stargz Snapshotter.html">
            
                    
                        <b>1.9.36.1.</b>
                    
                    Containerd Stargz Snapshotter
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.36.2" data-path="../镜像/OCI.html">
            
                <a href="../镜像/OCI.html">
            
                    
                        <b>1.9.36.2.</b>
                    
                    OCI
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.36.3" data-path="../镜像/harbor/">
            
                <a href="../镜像/harbor/">
            
                    
                        <b>1.9.36.3.</b>
                    
                    Harbor
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.36.3.1" data-path="../镜像/harbor/readme.html">
            
                <a href="../镜像/harbor/readme.html">
            
                    
                        <b>1.9.36.3.1.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9.36.4" data-path="../镜像/readme.html">
            
                <a href="../镜像/readme.html">
            
                    
                        <b>1.9.36.4.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.36.5" data-path="../镜像/自动构建镜像.html">
            
                <a href="../镜像/自动构建镜像.html">
            
                    
                        <b>1.9.36.5.</b>
                    
                    自动构建镜像
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.36.6" data-path="../镜像/镜像加速方案.html">
            
                <a href="../镜像/镜像加速方案.html">
            
                    
                        <b>1.9.36.6.</b>
                    
                    镜像加速方案
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.36.7" data-path="../镜像/镜像延迟加载技术解析.html">
            
                <a href="../镜像/镜像延迟加载技术解析.html">
            
                    
                        <b>1.9.36.7.</b>
                    
                    镜像延迟加载技术解析
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../../math/">
            
                <a href="../../math/">
            
                    
                        <b>1.10.</b>
                    
                    Math
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="../../math/readme.html">
            
                <a href="../../math/readme.html">
            
                    
                        <b>1.10.1.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.2" data-path="../../math/泊松分布.html">
            
                <a href="../../math/泊松分布.html">
            
                    
                        <b>1.10.2.</b>
                    
                    泊松分布
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../../效率/">
            
                <a href="../../效率/">
            
                    
                        <b>1.11.</b>
                    
                    效率
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.11.1" data-path="../../效率/cat.html">
            
                <a href="../../效率/cat.html">
            
                    
                        <b>1.11.1.</b>
                    
                    Cat
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2" data-path="../../效率/docker volume clean.html">
            
                <a href="../../效率/docker volume clean.html">
            
                    
                        <b>1.11.2.</b>
                    
                    Docker Volume Clean
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.3" data-path="../../效率/git book.html">
            
                <a href="../../效率/git book.html">
            
                    
                        <b>1.11.3.</b>
                    
                    Git Book
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.4" data-path="../../效率/git.html">
            
                <a href="../../效率/git.html">
            
                    
                        <b>1.11.4.</b>
                    
                    Git
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.5" data-path="../../效率/linux command.html">
            
                <a href="../../效率/linux command.html">
            
                    
                        <b>1.11.5.</b>
                    
                    Linux Command
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.6" data-path="../../效率/linux 内核.html">
            
                <a href="../../效率/linux 内核.html">
            
                    
                        <b>1.11.6.</b>
                    
                    Linux 内核
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.7" data-path="../../效率/macos path.html">
            
                <a href="../../效率/macos path.html">
            
                    
                        <b>1.11.7.</b>
                    
                    Macos Path
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.8" data-path="../../效率/nfs.html">
            
                <a href="../../效率/nfs.html">
            
                    
                        <b>1.11.8.</b>
                    
                    Nfs
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.9" data-path="../../效率/nginx.html">
            
                <a href="../../效率/nginx.html">
            
                    
                        <b>1.11.9.</b>
                    
                    Nginx
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.10" data-path="../../效率/nginx2.html">
            
                <a href="../../效率/nginx2.html">
            
                    
                        <b>1.11.10.</b>
                    
                    Nginx2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.11" data-path="../../效率/oauth2.html">
            
                <a href="../../效率/oauth2.html">
            
                    
                        <b>1.11.11.</b>
                    
                    Oauth2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.12" data-path="../../效率/ovftool.html">
            
                <a href="../../效率/ovftool.html">
            
                    
                        <b>1.11.12.</b>
                    
                    Ovftool
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.13" data-path="../../效率/readme.html">
            
                <a href="../../效率/readme.html">
            
                    
                        <b>1.11.13.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.14" data-path="../../效率/sed.html">
            
                <a href="../../效率/sed.html">
            
                    
                        <b>1.11.14.</b>
                    
                    Sed
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.15" data-path="../../效率/shell_judge.html">
            
                <a href="../../效率/shell_judge.html">
            
                    
                        <b>1.11.15.</b>
                    
                    Shell Judge
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.16" data-path="../../效率/sshpass.html">
            
                <a href="../../效率/sshpass.html">
            
                    
                        <b>1.11.16.</b>
                    
                    Sshpass
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.17" data-path="../../效率/telepresence.html">
            
                <a href="../../效率/telepresence.html">
            
                    
                        <b>1.11.17.</b>
                    
                    Telepresence
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.18" data-path="../../效率/typora.html">
            
                <a href="../../效率/typora.html">
            
                    
                        <b>1.11.18.</b>
                    
                    Typora
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.19" data-path="../../效率/url encode.html">
            
                <a href="../../效率/url encode.html">
            
                    
                        <b>1.11.19.</b>
                    
                    Url Encode
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.20" data-path="../../效率/vim.html">
            
                <a href="../../效率/vim.html">
            
                    
                        <b>1.11.20.</b>
                    
                    Vim
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.21" data-path="../../效率/yum.html">
            
                <a href="../../效率/yum.html">
            
                    
                        <b>1.11.21.</b>
                    
                    Yum
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.22" data-path="../../效率/内网穿透.html">
            
                <a href="../../效率/内网穿透.html">
            
                    
                        <b>1.11.22.</b>
                    
                    内网穿透
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.23" data-path="../../效率/科学上网.html">
            
                <a href="../../效率/科学上网.html">
            
                    
                        <b>1.11.23.</b>
                    
                    科学上网
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.24" data-path="../../效率/证书制作.html">
            
                <a href="../../效率/证书制作.html">
            
                    
                        <b>1.11.24.</b>
                    
                    证书制作
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.12" >
            
                <span>
            
                    
                        <b>1.12.</b>
                    
                    杂谈
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.12.1" data-path="../../杂谈/论好文章和烂文章.html">
            
                <a href="../../杂谈/论好文章和烂文章.html">
            
                    
                        <b>1.12.1.</b>
                    
                    论好文章和烂文章
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="../../测试/">
            
                <a href="../../测试/">
            
                    
                        <b>1.13.</b>
                    
                    测试
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.13.1" data-path="../../测试/ginkgo/">
            
                <a href="../../测试/ginkgo/">
            
                    
                        <b>1.13.1.</b>
                    
                    Ginkgo
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.13.1.1" data-path="../../测试/ginkgo/ginkgo.html">
            
                <a href="../../测试/ginkgo/ginkgo.html">
            
                    
                        <b>1.13.1.1.</b>
                    
                    Ginkgo
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.1.2" data-path="../../测试/ginkgo/ginkgo_cmd.html">
            
                <a href="../../测试/ginkgo/ginkgo_cmd.html">
            
                    
                        <b>1.13.1.2.</b>
                    
                    Ginkgo Cmd
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.1.3" data-path="../../测试/ginkgo/readme.html">
            
                <a href="../../测试/ginkgo/readme.html">
            
                    
                        <b>1.13.1.3.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.13.2" data-path="../../测试/golang-test.html">
            
                <a href="../../测试/golang-test.html">
            
                    
                        <b>1.13.2.</b>
                    
                    Golang Test
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.3" data-path="../../测试/http测试.html">
            
                <a href="../../测试/http测试.html">
            
                    
                        <b>1.13.3.</b>
                    
                    Http测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.4" data-path="../../测试/readme.html">
            
                <a href="../../测试/readme.html">
            
                    
                        <b>1.13.4.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.5" data-path="../../测试/其他功能.html">
            
                <a href="../../测试/其他功能.html">
            
                    
                        <b>1.13.5.</b>
                    
                    其他功能
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.6" data-path="../../测试/单元测试.html">
            
                <a href="../../测试/单元测试.html">
            
                    
                        <b>1.13.6.</b>
                    
                    单元测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.7" data-path="../../测试/单元测试2.html">
            
                <a href="../../测试/单元测试2.html">
            
                    
                        <b>1.13.7.</b>
                    
                    单元测试2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.8" data-path="../../测试/基准测试.html">
            
                <a href="../../测试/基准测试.html">
            
                    
                        <b>1.13.8.</b>
                    
                    基准测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.9" data-path="../../测试/子测试与子基准测试.html">
            
                <a href="../../测试/子测试与子基准测试.html">
            
                    
                        <b>1.13.9.</b>
                    
                    子测试与子基准测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.10" data-path="../../测试/并行测试.html">
            
                <a href="../../测试/并行测试.html">
            
                    
                        <b>1.13.10.</b>
                    
                    并行测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.11" data-path="../../测试/质量检查/">
            
                <a href="../../测试/质量检查/">
            
                    
                        <b>1.13.11.</b>
                    
                    质量检查
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.13.11.1" data-path="../../测试/质量检查/Sonar.html">
            
                <a href="../../测试/质量检查/Sonar.html">
            
                    
                        <b>1.13.11.1.</b>
                    
                    Sonar
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.11.2" data-path="../../测试/质量检查/go_lint.html">
            
                <a href="../../测试/质量检查/go_lint.html">
            
                    
                        <b>1.13.11.2.</b>
                    
                    Go Lint
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.11.3" data-path="../../测试/质量检查/readme.html">
            
                <a href="../../测试/质量检查/readme.html">
            
                    
                        <b>1.13.11.3.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="../../规范/">
            
                <a href="../../规范/">
            
                    
                        <b>1.14.</b>
                    
                    规范
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.14.1" data-path="../../规范/CodeReviewComments.html">
            
                <a href="../../规范/CodeReviewComments.html">
            
                    
                        <b>1.14.1.</b>
                    
                    CodeReviewComments
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.2" data-path="../../规范/git规范.html">
            
                <a href="../../规范/git规范.html">
            
                    
                        <b>1.14.2.</b>
                    
                    Git规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.3" data-path="../../规范/golang 代码规范.html">
            
                <a href="../../规范/golang 代码规范.html">
            
                    
                        <b>1.14.3.</b>
                    
                    Golang 代码规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.4" data-path="../../规范/readme.html">
            
                <a href="../../规范/readme.html">
            
                    
                        <b>1.14.4.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.5" data-path="../../规范/代码走读.html">
            
                <a href="../../规范/代码走读.html">
            
                    
                        <b>1.14.5.</b>
                    
                    代码走读
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="../../设计模式/">
            
                <a href="../../设计模式/">
            
                    
                        <b>1.15.</b>
                    
                    设计模式
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.15.1" data-path="../../设计模式/readme.html">
            
                <a href="../../设计模式/readme.html">
            
                    
                        <b>1.15.1.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.2" data-path="../../设计模式/创建模型/">
            
                <a href="../../设计模式/创建模型/">
            
                    
                        <b>1.15.2.</b>
                    
                    创建模型
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.15.2.1" data-path="../../设计模式/创建模型/readme.html">
            
                <a href="../../设计模式/创建模型/readme.html">
            
                    
                        <b>1.15.2.1.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.2.2" data-path="../../设计模式/创建模型/创建者模型.html">
            
                <a href="../../设计模式/创建模型/创建者模型.html">
            
                    
                        <b>1.15.2.2.</b>
                    
                    创建者模型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.2.3" data-path="../../设计模式/创建模型/单例模式.html">
            
                <a href="../../设计模式/创建模型/单例模式.html">
            
                    
                        <b>1.15.2.3.</b>
                    
                    单例模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.2.4" data-path="../../设计模式/创建模型/原型模式.html">
            
                <a href="../../设计模式/创建模型/原型模式.html">
            
                    
                        <b>1.15.2.4.</b>
                    
                    原型模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.2.5" data-path="../../设计模式/创建模型/工厂方法.html">
            
                <a href="../../设计模式/创建模型/工厂方法.html">
            
                    
                        <b>1.15.2.5.</b>
                    
                    工厂方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.2.6" data-path="../../设计模式/创建模型/抽象工厂.html">
            
                <a href="../../设计模式/创建模型/抽象工厂.html">
            
                    
                        <b>1.15.2.6.</b>
                    
                    抽象工厂
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.2.7" data-path="../../设计模式/创建模型/简单工厂.html">
            
                <a href="../../设计模式/创建模型/简单工厂.html">
            
                    
                        <b>1.15.2.7.</b>
                    
                    简单工厂
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.15.3" data-path="../../设计模式/结构型模型/">
            
                <a href="../../设计模式/结构型模型/">
            
                    
                        <b>1.15.3.</b>
                    
                    结构型模型
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.15.3.1" data-path="../../设计模式/结构型模型/readme.html">
            
                <a href="../../设计模式/结构型模型/readme.html">
            
                    
                        <b>1.15.3.1.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.3.2" data-path="../../设计模式/结构型模型/享元模式.html">
            
                <a href="../../设计模式/结构型模型/享元模式.html">
            
                    
                        <b>1.15.3.2.</b>
                    
                    享元模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.3.3" data-path="../../设计模式/结构型模型/代理模式.html">
            
                <a href="../../设计模式/结构型模型/代理模式.html">
            
                    
                        <b>1.15.3.3.</b>
                    
                    代理模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.3.4" data-path="../../设计模式/结构型模型/外观模式.html">
            
                <a href="../../设计模式/结构型模型/外观模式.html">
            
                    
                        <b>1.15.3.4.</b>
                    
                    外观模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.3.5" data-path="../../设计模式/结构型模型/桥模式.html">
            
                <a href="../../设计模式/结构型模型/桥模式.html">
            
                    
                        <b>1.15.3.5.</b>
                    
                    桥模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.3.6" data-path="../../设计模式/结构型模型/组合模式.html">
            
                <a href="../../设计模式/结构型模型/组合模式.html">
            
                    
                        <b>1.15.3.6.</b>
                    
                    组合模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.3.7" data-path="../../设计模式/结构型模型/装饰模式.html">
            
                <a href="../../设计模式/结构型模型/装饰模式.html">
            
                    
                        <b>1.15.3.7.</b>
                    
                    装饰模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.3.8" data-path="../../设计模式/结构型模型/适配器模式.html">
            
                <a href="../../设计模式/结构型模型/适配器模式.html">
            
                    
                        <b>1.15.3.8.</b>
                    
                    适配器模式
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.15.4" data-path="../../设计模式/行为型模型/">
            
                <a href="../../设计模式/行为型模型/">
            
                    
                        <b>1.15.4.</b>
                    
                    行为型模型
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.15.4.1" data-path="../../设计模式/行为型模型/readme.html">
            
                <a href="../../设计模式/行为型模型/readme.html">
            
                    
                        <b>1.15.4.1.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.4.2" data-path="../../设计模式/行为型模型/中介者模式.html">
            
                <a href="../../设计模式/行为型模型/中介者模式.html">
            
                    
                        <b>1.15.4.2.</b>
                    
                    中介者模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.4.3" data-path="../../设计模式/行为型模型/命令模式.html">
            
                <a href="../../设计模式/行为型模型/命令模式.html">
            
                    
                        <b>1.15.4.3.</b>
                    
                    命令模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.4.4" data-path="../../设计模式/行为型模型/备忘录模式.html">
            
                <a href="../../设计模式/行为型模型/备忘录模式.html">
            
                    
                        <b>1.15.4.4.</b>
                    
                    备忘录模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.4.5" data-path="../../设计模式/行为型模型/模板方法模式.html">
            
                <a href="../../设计模式/行为型模型/模板方法模式.html">
            
                    
                        <b>1.15.4.5.</b>
                    
                    模板方法模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.4.6" data-path="../../设计模式/行为型模型/状态模式.html">
            
                <a href="../../设计模式/行为型模型/状态模式.html">
            
                    
                        <b>1.15.4.6.</b>
                    
                    状态模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.4.7" data-path="../../设计模式/行为型模型/策略模式.html">
            
                <a href="../../设计模式/行为型模型/策略模式.html">
            
                    
                        <b>1.15.4.7.</b>
                    
                    策略模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.4.8" data-path="../../设计模式/行为型模型/职责链模式.html">
            
                <a href="../../设计模式/行为型模型/职责链模式.html">
            
                    
                        <b>1.15.4.8.</b>
                    
                    职责链模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.4.9" data-path="../../设计模式/行为型模型/观察者模式.html">
            
                <a href="../../设计模式/行为型模型/观察者模式.html">
            
                    
                        <b>1.15.4.9.</b>
                    
                    观察者模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.4.10" data-path="../../设计模式/行为型模型/解释器模式.html">
            
                <a href="../../设计模式/行为型模型/解释器模式.html">
            
                    
                        <b>1.15.4.10.</b>
                    
                    解释器模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.4.11" data-path="../../设计模式/行为型模型/访问者模式.html">
            
                <a href="../../设计模式/行为型模型/访问者模式.html">
            
                    
                        <b>1.15.4.11.</b>
                    
                    访问者模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.4.12" data-path="../../设计模式/行为型模型/迭代器模式.html">
            
                <a href="../../设计模式/行为型模型/迭代器模式.html">
            
                    
                        <b>1.15.4.12.</b>
                    
                    迭代器模式
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../../.." >Garbage Collector Controller 源码分析</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-anchor"></i><ul><li><a href="#garbage-collector-controller-&#x6E90;&#x7801;&#x5206;&#x6790;">garbage collector controller &#x6E90;&#x7801;&#x5206;&#x6790;</a></li></ul></div><a href="#garbage-collector-controller-&#x6E90;&#x7801;&#x5206;&#x6790;" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><h1 id="garbage-collector-controller-&#x6E90;&#x7801;&#x5206;&#x6790;"><a name="garbage-collector-controller-&#x6E90;&#x7801;&#x5206;&#x6790;" class="anchor-navigation-ex-anchor" href="#garbage-collector-controller-&#x6E90;&#x7801;&#x5206;&#x6790;"><i class="fa fa-link" aria-hidden="true"></i></a>garbage collector controller &#x6E90;&#x7801;&#x5206;&#x6790;</h1>
<!-- toc -->
<ul>
<li><a href="#kubernetes-%E4%B8%AD%E7%9A%84%E5%88%A0%E9%99%A4%E7%AD%96%E7%95%A5">kubernetes &#x4E2D;&#x7684;&#x5220;&#x9664;&#x7B56;&#x7565;</a></li>
<li><a href="#garbagecollectorcontroller-%E6%BA%90%E7%A0%81%E5%88%86%E6%9E%90">GarbageCollectorController &#x6E90;&#x7801;&#x5206;&#x6790;</a></li>
<li><a href="#%E7%A4%BA%E4%BE%8B">&#x793A;&#x4F8B;</a></li>
<li><a href="#%E6%80%BB%E7%BB%93">&#x603B;&#x7ED3;</a></li>
</ul>
<!-- tocstop -->
<p><a href="https://www.bookstack.cn/read/source-code-reading-notes/kubernetes-garbagecollector_controller.md" target="_blank">&#x539F;&#x6587;&#x7AE0;</a></p>
<p>&#x5728;&#x524D;&#x9762;&#x51E0;&#x7BC7;&#x5173;&#x4E8E; controller &#x6E90;&#x7801;&#x5206;&#x6790;&#x7684;&#x6587;&#x7AE0;&#x4E2D;&#x591A;&#x6B21;&#x63D0;&#x5230;&#x4E86;&#x5F53;&#x5220;&#x9664;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x65F6;&#xFF0C;&#x5176;&#x5BF9;&#x5E94;&#x7684; controller &#x5E76;&#x4E0D;&#x4F1A;&#x6267;&#x884C;&#x5220;&#x9664;&#x5BF9;&#x8C61;&#x7684;&#x64CD;&#x4F5C;&#xFF0C;&#x5728; kubernetes &#x4E2D;&#x5BF9;&#x8C61;&#x7684;&#x56DE;&#x6536;&#x64CD;&#x4F5C;&#x662F;&#x7531; GarbageCollectorController &#x8D1F;&#x8D23;&#x7684;&#xFF0C;&#x5176;&#x4F5C;&#x7528;&#x5C31;&#x662F;&#x5F53;&#x5220;&#x9664;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x65F6;&#xFF0C;&#x4F1A;&#x6839;&#x636E;&#x6307;&#x5B9A;&#x7684;&#x5220;&#x9664;&#x7B56;&#x7565;&#x56DE;&#x6536;&#x8BE5;&#x5BF9;&#x8C61;&#x53CA;&#x5176;&#x4F9D;&#x8D56;&#x5BF9;&#x8C61;&#xFF0C;&#x672C;&#x6587;&#x4F1A;&#x6DF1;&#x5165;&#x5206;&#x6790;&#x5783;&#x573E;&#x6536;&#x96C6;&#x80CC;&#x540E;&#x7684;&#x5B9E;&#x73B0;&#x3002;</p>
<h3 id="kubernetes-&#x4E2D;&#x7684;&#x5220;&#x9664;&#x7B56;&#x7565;"><a name="kubernetes-&#x4E2D;&#x7684;&#x5220;&#x9664;&#x7B56;&#x7565;" class="anchor-navigation-ex-anchor" href="#kubernetes-&#x4E2D;&#x7684;&#x5220;&#x9664;&#x7B56;&#x7565;"><i class="fa fa-link" aria-hidden="true"></i></a>kubernetes &#x4E2D;&#x7684;&#x5220;&#x9664;&#x7B56;&#x7565;</h3>
<p>kubernetes &#x4E2D;&#x6709;&#x4E09;&#x79CD;&#x5220;&#x9664;&#x7B56;&#x7565;&#xFF1A;<code>Orphan</code>&#x3001;<code>Foreground</code> &#x548C; <code>Background</code>&#xFF0C;&#x4E09;&#x79CD;&#x5220;&#x9664;&#x7B56;&#x7565;&#x7684;&#x610F;&#x4E49;&#x5206;&#x522B;&#x4E3A;&#xFF1A;</p>
<ul>
<li><code>Orphan</code> &#x7B56;&#x7565;&#xFF1A;&#x975E;&#x7EA7;&#x8054;&#x5220;&#x9664;&#xFF0C;&#x5220;&#x9664;&#x5BF9;&#x8C61;&#x65F6;&#xFF0C;&#x4E0D;&#x4F1A;&#x81EA;&#x52A8;&#x5220;&#x9664;&#x5B83;&#x7684;&#x4F9D;&#x8D56;&#x6216;&#x8005;&#x662F;&#x5B50;&#x5BF9;&#x8C61;&#xFF0C;&#x8FD9;&#x4E9B;&#x4F9D;&#x8D56;&#x88AB;&#x79F0;&#x4F5C;&#x662F;&#x539F;&#x5BF9;&#x8C61;&#x7684;&#x5B64;&#x513F;&#x5BF9;&#x8C61;&#xFF0C;&#x4F8B;&#x5982;&#x5F53;&#x6267;&#x884C;&#x4EE5;&#x4E0B;&#x547D;&#x4EE4;&#x65F6;&#x4F1A;&#x4F7F;&#x7528; <code>Orphan</code> &#x7B56;&#x7565;&#x8FDB;&#x884C;&#x5220;&#x9664;&#xFF0C;&#x6B64;&#x65F6; ds &#x7684;&#x4F9D;&#x8D56;&#x5BF9;&#x8C61; <code>controllerrevision</code> &#x4E0D;&#x4F1A;&#x88AB;&#x5220;&#x9664;&#xFF1B;</li>
</ul>
<pre class="language-"><code>$ kubectl delete ds/nginx-ds --cascade=false
</code></pre><ul>
<li><code>Background</code> &#x7B56;&#x7565;&#xFF1A;&#x5728;&#x8BE5;&#x6A21;&#x5F0F;&#x4E0B;&#xFF0C;kubernetes &#x4F1A;&#x7ACB;&#x5373;&#x5220;&#x9664;&#x8BE5;&#x5BF9;&#x8C61;&#xFF0C;&#x7136;&#x540E;&#x5783;&#x573E;&#x6536;&#x96C6;&#x5668;&#x4F1A;&#x5728;&#x540E;&#x53F0;&#x5220;&#x9664;&#x8FD9;&#x4E9B;&#x8BE5;&#x5BF9;&#x8C61;&#x7684;&#x4F9D;&#x8D56;&#x5BF9;&#x8C61;&#xFF1B;</li>
<li><code>Foreground</code> &#x7B56;&#x7565;&#xFF1A;&#x5728;&#x8BE5;&#x6A21;&#x5F0F;&#x4E0B;&#xFF0C;&#x5BF9;&#x8C61;&#x9996;&#x5148;&#x8FDB;&#x5165;&#x201C;&#x5220;&#x9664;&#x4E2D;&#x201D;&#x72B6;&#x6001;&#xFF0C;&#x5373;&#x4F1A;&#x8BBE;&#x7F6E;&#x5BF9;&#x8C61;&#x7684; <code>deletionTimestamp</code> &#x5B57;&#x6BB5;&#x5E76;&#x4E14;&#x5BF9;&#x8C61;&#x7684; <code>metadata.finalizers</code> &#x5B57;&#x6BB5;&#x5305;&#x542B;&#x4E86;&#x503C; &#x201C;foregroundDeletion&#x201D;&#xFF0C;&#x6B64;&#x65F6;&#x8BE5;&#x5BF9;&#x8C61;&#x4F9D;&#x7136;&#x5B58;&#x5728;&#xFF0C;&#x7136;&#x540E;&#x5783;&#x573E;&#x6536;&#x96C6;&#x5668;&#x4F1A;&#x5220;&#x9664;&#x8BE5;&#x5BF9;&#x8C61;&#x7684;&#x6240;&#x6709;&#x4F9D;&#x8D56;&#x5BF9;&#x8C61;&#xFF0C;&#x5783;&#x573E;&#x6536;&#x96C6;&#x5668;&#x5728;&#x5220;&#x9664;&#x4E86;&#x6240;&#x6709;&#x201C;Blocking&#x201D; &#x72B6;&#x6001;&#x7684;&#x4F9D;&#x8D56;&#x5BF9;&#x8C61;&#xFF08;&#x6307;&#x5176;&#x5B50;&#x5BF9;&#x8C61;&#x4E2D; <code>ownerReference.blockOwnerDeletion=true</code>&#x7684;&#x5BF9;&#x8C61;&#xFF09;&#x4E4B;&#x540E;&#xFF0C;&#x7136;&#x540E;&#x624D;&#x4F1A;&#x5220;&#x9664;&#x5BF9;&#x8C61;&#x672C;&#x8EAB;&#xFF1B;</li>
</ul>
<p>&#x5728; v1.9 &#x4EE5;&#x524D;&#x7684;&#x7248;&#x672C;&#x4E2D;&#xFF0C;&#x5927;&#x90E8;&#x5206; controller &#x9ED8;&#x8BA4;&#x7684;&#x5220;&#x9664;&#x7B56;&#x7565;&#x4E3A; <code>Orphan</code>&#xFF0C;&#x4ECE; v1.9 &#x5F00;&#x59CB;&#xFF0C;&#x5BF9;&#x4E8E; apps/v1 &#x4E0B;&#x7684;&#x8D44;&#x6E90;&#x9ED8;&#x8BA4;&#x4F7F;&#x7528; <code>Background</code> &#x6A21;&#x5F0F;&#x3002;&#x4EE5;&#x4E0A;&#x4E09;&#x79CD;&#x5220;&#x9664;&#x7B56;&#x7565;&#x90FD;&#x53EF;&#x4EE5;&#x5728;&#x5220;&#x9664;&#x5BF9;&#x8C61;&#x65F6;&#x901A;&#x8FC7;&#x8BBE;&#x7F6E; <code>deleteOptions.propagationPolicy</code> &#x5B57;&#x6BB5;&#x8FDB;&#x884C;&#x6307;&#x5B9A;&#xFF0C;&#x5982;&#x4E0B;&#x6240;&#x793A;&#xFF1A;</p>
<pre class="language-"><code>$ curl -k -v -XDELETE  -H &quot;Accept: application/json&quot; -H &quot;Content-Type: application/json&quot; -d &apos;{&quot;propagationPolicy&quot;:&quot;Foreground&quot;}&apos; &apos;https://192.168.99.108:8443/apis/apps/v1/namespaces/default/daemonsets/nginx-ds&apos;
</code></pre><h4 id="finalizer-&#x673A;&#x5236;"><a name="finalizer-&#x673A;&#x5236;" class="anchor-navigation-ex-anchor" href="#finalizer-&#x673A;&#x5236;"><i class="fa fa-link" aria-hidden="true"></i></a>finalizer &#x673A;&#x5236;</h4>
<p>finalizer &#x662F;&#x5728;&#x5220;&#x9664;&#x5BF9;&#x8C61;&#x65F6;&#x8BBE;&#x7F6E;&#x7684;&#x4E00;&#x4E2A; hook&#xFF0C;&#x5176;&#x76EE;&#x7684;&#x662F;&#x4E3A;&#x4E86;&#x8BA9;&#x5BF9;&#x8C61;&#x5728;&#x5220;&#x9664;&#x524D;&#x786E;&#x8BA4;&#x5176;&#x5B50;&#x5BF9;&#x8C61;&#x5DF2;&#x7ECF;&#x88AB;&#x5B8C;&#x5168;&#x5220;&#x9664;&#xFF0C;k8s &#x4E2D;&#x9ED8;&#x8BA4;&#x6709;&#x4E24;&#x79CD; finalizer&#xFF1A;<code>OrphanFinalizer</code> &#x548C; <code>ForegroundFinalizer</code>&#xFF0C;finalizer &#x5B58;&#x5728;&#x4E8E;&#x5BF9;&#x8C61;&#x7684; ObjectMeta &#x4E2D;&#xFF0C;&#x5F53;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x7684;&#x4F9D;&#x8D56;&#x5BF9;&#x8C61;&#x88AB;&#x5220;&#x9664;&#x540E;&#x5176;&#x5BF9;&#x5E94;&#x7684; finalizers &#x5B57;&#x6BB5;&#x4E5F;&#x4F1A;&#x88AB;&#x79FB;&#x9664;&#xFF0C;&#x53EA;&#x6709; finalizers &#x5B57;&#x6BB5;&#x4E3A;&#x7A7A;&#x65F6;&#xFF0C;apiserver &#x624D;&#x4F1A;&#x5220;&#x9664;&#x8BE5;&#x5BF9;&#x8C61;&#x3002;</p>
<pre class="language-"><code>{
......
&quot;metadata&quot;:{
......
&quot;finalizers&quot;:[
&quot;foregroundDeletion&quot;
]
}
......
}
</code></pre><p>&#x6B64;&#x5916;&#xFF0C;finalizer &#x4E0D;&#x4EC5;&#x4EC5;&#x652F;&#x6301;&#x4EE5;&#x4E0A;&#x4E24;&#x79CD;&#x5B57;&#x6BB5;&#xFF0C;&#x5728;&#x4F7F;&#x7528;&#x81EA;&#x5B9A;&#x4E49; controller &#x65F6;&#x4E5F;&#x53EF;&#x4EE5;&#x5728; CR &#x4E2D;&#x8BBE;&#x7F6E;&#x81EA;&#x5B9A;&#x4E49;&#x7684; finalizer &#x6807;&#x8BC6;&#x3002;</p>
<h3 id="garbagecollectorcontroller-&#x6E90;&#x7801;&#x5206;&#x6790;"><a name="garbagecollectorcontroller-&#x6E90;&#x7801;&#x5206;&#x6790;" class="anchor-navigation-ex-anchor" href="#garbagecollectorcontroller-&#x6E90;&#x7801;&#x5206;&#x6790;"><i class="fa fa-link" aria-hidden="true"></i></a>GarbageCollectorController &#x6E90;&#x7801;&#x5206;&#x6790;</h3>
<blockquote>
<p>kubernetes &#x7248;&#x672C;&#xFF1A;v1.16</p>
</blockquote>
<p>GarbageCollectorController &#x8D1F;&#x8D23;&#x56DE;&#x6536; kubernetes &#x4E2D;&#x7684;&#x8D44;&#x6E90;&#xFF0C;&#x8981;&#x56DE;&#x6536; kubernetes &#x4E2D;&#x6240;&#x6709;&#x8D44;&#x6E90;&#x9996;&#x5148;&#x5F97;&#x76D1;&#x63A7;&#x6240;&#x6709;&#x8D44;&#x6E90;&#xFF0C;GarbageCollectorController &#x4F1A;&#x76D1;&#x542C;&#x96C6;&#x7FA4;&#x4E2D;&#x6240;&#x6709;&#x53EF;&#x5220;&#x9664;&#x8D44;&#x6E90;&#x4EA7;&#x751F;&#x7684;&#x6240;&#x6709;&#x4E8B;&#x4EF6;&#xFF0C;&#x8FD9;&#x4E9B;&#x4E8B;&#x4EF6;&#x4F1A;&#x88AB;&#x653E;&#x5165;&#x5230;&#x4E00;&#x4E2A;&#x961F;&#x5217;&#x4E2D;&#xFF0C;&#x7136;&#x540E; controller &#x4F1A;&#x542F;&#x52A8;&#x591A;&#x4E2A; goroutine &#x5904;&#x7406;&#x961F;&#x5217;&#x4E2D;&#x7684;&#x4E8B;&#x4EF6;&#xFF0C;&#x82E5;&#x4E3A;&#x5220;&#x9664;&#x4E8B;&#x4EF6;&#x4F1A;&#x6839;&#x636E;&#x5BF9;&#x8C61;&#x7684;&#x5220;&#x9664;&#x7B56;&#x7565;&#x5220;&#x9664;&#x5173;&#x8054;&#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x5BF9;&#x4E8E;&#x975E;&#x5220;&#x9664;&#x4E8B;&#x4EF6;&#x4F1A;&#x66F4;&#x65B0;&#x5BF9;&#x8C61;&#x4E4B;&#x95F4;&#x7684;&#x4F9D;&#x8D56;&#x5173;&#x7CFB;&#x3002;</p>
<h4 id="startgarbagecollectorcontroller"><a name="startgarbagecollectorcontroller" class="anchor-navigation-ex-anchor" href="#startgarbagecollectorcontroller"><i class="fa fa-link" aria-hidden="true"></i></a>startGarbageCollectorController</h4>
<p>&#x9996;&#x5148;&#x8FD8;&#x662F;&#x770B; GarbageCollectorController &#x7684;&#x542F;&#x52A8;&#x65B9;&#x6CD5; <code>startGarbageCollectorController</code>&#xFF0C;&#x5176;&#x4E3B;&#x8981;&#x903B;&#x8F91;&#x4E3A;&#xFF1A;</p>
<ul>
<li>1&#x3001;&#x521D;&#x59CB;&#x5316; discoveryClient&#xFF0C;discoveryClient &#x4E3B;&#x8981;&#x7528;&#x6765;&#x83B7;&#x53D6;&#x96C6;&#x7FA4;&#x4E2D;&#x7684;&#x6240;&#x6709;&#x8D44;&#x6E90;&#xFF1B;</li>
<li>2&#x3001;&#x8C03;&#x7528; <code>garbagecollector.GetDeletableResources</code> &#x83B7;&#x53D6;&#x96C6;&#x7FA4;&#x5185;&#x6240;&#x6709;&#x53EF;&#x5220;&#x9664;&#x7684;&#x8D44;&#x6E90;&#x5BF9;&#x8C61;&#xFF0C;&#x652F;&#x6301; &#x201C;delete&#x201D;, &#x201C;list&#x201D;, &#x201C;watch&#x201D; &#x4E09;&#x79CD;&#x64CD;&#x4F5C;&#x7684; resource &#x79F0;&#x4E3A; <code>deletableResource</code>&#xFF1B;</li>
<li>3&#x3001;&#x8C03;&#x7528; <code>garbagecollector.NewGarbageCollector</code> &#x521D;&#x59CB;&#x5316; garbageCollector &#x5BF9;&#x8C61;&#xFF1B;</li>
<li>4&#x3001;&#x8C03;&#x7528; <code>garbageCollector.Run</code> &#x542F;&#x52A8; garbageCollector&#xFF1B;</li>
<li>5&#x3001;&#x8C03;&#x7528; <code>garbageCollector.Sync</code> &#x76D1;&#x542C;&#x96C6;&#x7FA4;&#x4E2D;&#x7684; <code>DeletableResources</code> &#xFF0C;&#x5F53;&#x51FA;&#x73B0;&#x65B0;&#x7684; <code>DeletableResources</code> &#x65F6;&#x540C;&#x6B65;&#x5230; monitors &#x4E2D;&#xFF0C;&#x786E;&#x4FDD;&#x76D1;&#x63A7;&#x96C6;&#x7FA4;&#x4E2D;&#x7684;&#x6240;&#x6709;&#x8D44;&#x6E90;&#xFF1B;</li>
<li>6&#x3001;&#x8C03;&#x7528; <code>garbagecollector.NewDebugHandler</code> &#x6CE8;&#x518C; debug &#x63A5;&#x53E3;&#xFF0C;&#x7528;&#x6765;&#x63D0;&#x4F9B;&#x96C6;&#x7FA4;&#x5185;&#x6240;&#x6709;&#x5BF9;&#x8C61;&#x7684;&#x5173;&#x8054;&#x5173;&#x7CFB;&#xFF1B;</li>
</ul>
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token function">startGarbageCollectorController</span><span class="token punctuation">(</span>ctx ControllerContext<span class="token punctuation">)</span><span class="token punctuation">(</span>http<span class="token punctuation">.</span>Handler<span class="token punctuation">,</span><span class="token builtin">bool</span><span class="token punctuation">,</span> <span class="token builtin">error</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
<span class="token keyword">if</span><span class="token operator">!</span>ctx<span class="token punctuation">.</span>ComponentConfig<span class="token punctuation">.</span>GarbageCollectorController<span class="token punctuation">.</span>EnableGarbageCollector<span class="token punctuation">{</span>
returnnil<span class="token punctuation">,</span><span class="token boolean">false</span><span class="token punctuation">,</span><span class="token boolean">nil</span>
<span class="token punctuation">}</span>
<span class="token comment">// 1&#x3001;&#x521D;&#x59CB;&#x5316; discoveryClient</span>
    gcClientset <span class="token operator">:=</span> ctx<span class="token punctuation">.</span>ClientBuilder<span class="token punctuation">.</span><span class="token function">ClientOrDie</span><span class="token punctuation">(</span><span class="token string">&quot;generic-garbage-collector&quot;</span><span class="token punctuation">)</span>
    discoveryClient <span class="token operator">:=</span> cacheddiscovery<span class="token punctuation">.</span><span class="token function">NewMemCacheClient</span><span class="token punctuation">(</span>gcClientset<span class="token punctuation">.</span><span class="token function">Discovery</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
    config <span class="token operator">:=</span> ctx<span class="token punctuation">.</span>ClientBuilder<span class="token punctuation">.</span><span class="token function">ConfigOrDie</span><span class="token punctuation">(</span><span class="token string">&quot;generic-garbage-collector&quot;</span><span class="token punctuation">)</span>
    metadataClient<span class="token punctuation">,</span> err <span class="token operator">:=</span> metadata<span class="token punctuation">.</span><span class="token function">NewForConfig</span><span class="token punctuation">(</span>config<span class="token punctuation">)</span>
<span class="token keyword">if</span> err <span class="token operator">!=</span><span class="token boolean">nil</span><span class="token punctuation">{</span>
returnnil<span class="token punctuation">,</span><span class="token boolean">true</span><span class="token punctuation">,</span> err
<span class="token punctuation">}</span>
<span class="token comment">// 2&#x3001;&#x83B7;&#x53D6; deletableResource</span>
    deletableResources <span class="token operator">:=</span> garbagecollector<span class="token punctuation">.</span><span class="token function">GetDeletableResources</span><span class="token punctuation">(</span>discoveryClient<span class="token punctuation">)</span>
    ignoredResources <span class="token operator">:=</span> <span class="token function">make</span><span class="token punctuation">(</span><span class="token keyword">map</span><span class="token punctuation">[</span>schema<span class="token punctuation">.</span>GroupResource<span class="token punctuation">]</span><span class="token keyword">struct</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token keyword">for</span> <span class="token boolean">_</span><span class="token punctuation">,</span> r <span class="token operator">:=</span> <span class="token keyword">range</span> ctx<span class="token punctuation">.</span>ComponentConfig<span class="token punctuation">.</span>GarbageCollectorController<span class="token punctuation">.</span>GCIgnoredResources<span class="token punctuation">{</span>
        ignoredResources<span class="token punctuation">[</span>schema<span class="token punctuation">.</span>GroupResource<span class="token punctuation">{</span>Group<span class="token punctuation">:</span> r<span class="token punctuation">.</span>Group<span class="token punctuation">,</span>Resource<span class="token punctuation">:</span> r<span class="token punctuation">.</span>Resource<span class="token punctuation">}</span><span class="token punctuation">]</span><span class="token operator">=</span><span class="token keyword">struct</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">{</span><span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token comment">// 3&#x3001;&#x521D;&#x59CB;&#x5316; garbageCollector &#x5BF9;&#x8C61;</span>
    garbageCollector<span class="token punctuation">,</span> err <span class="token operator">:=</span> garbagecollector<span class="token punctuation">.</span><span class="token function">NewGarbageCollector</span><span class="token punctuation">(</span>
<span class="token operator">...</span><span class="token operator">...</span>
<span class="token punctuation">)</span>
<span class="token keyword">if</span> err <span class="token operator">!=</span><span class="token boolean">nil</span><span class="token punctuation">{</span>
returnnil<span class="token punctuation">,</span><span class="token boolean">true</span><span class="token punctuation">,</span> fmt<span class="token punctuation">.</span><span class="token function">Errorf</span><span class="token punctuation">(</span><span class="token string">&quot;failed to start the generic garbage collector: %v&quot;</span><span class="token punctuation">,</span> err<span class="token punctuation">)</span>
<span class="token punctuation">}</span>
<span class="token comment">// 4&#x3001;&#x542F;&#x52A8; garbage collector</span>
    workers <span class="token operator">:=</span><span class="token function">int</span><span class="token punctuation">(</span>ctx<span class="token punctuation">.</span>ComponentConfig<span class="token punctuation">.</span>GarbageCollectorController<span class="token punctuation">.</span>ConcurrentGCSyncs<span class="token punctuation">)</span>
    <span class="token keyword">go</span> garbageCollector<span class="token punctuation">.</span><span class="token function">Run</span><span class="token punctuation">(</span>workers<span class="token punctuation">,</span> ctx<span class="token punctuation">.</span>Stop<span class="token punctuation">)</span>
<span class="token comment">// 5&#x3001;&#x76D1;&#x542C;&#x96C6;&#x7FA4;&#x4E2D;&#x7684; DeletableResources</span>
    <span class="token keyword">go</span> garbageCollector<span class="token punctuation">.</span><span class="token function">Sync</span><span class="token punctuation">(</span>gcClientset<span class="token punctuation">.</span><span class="token function">Discovery</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token number">30</span><span class="token operator">*</span>time<span class="token punctuation">.</span>Second<span class="token punctuation">,</span> ctx<span class="token punctuation">.</span>Stop<span class="token punctuation">)</span>
<span class="token comment">// 6&#x3001;&#x6CE8;&#x518C; debug &#x63A5;&#x53E3;</span>
<span class="token keyword">return</span> garbagecollector<span class="token punctuation">.</span><span class="token function">NewDebugHandler</span><span class="token punctuation">(</span>garbageCollector<span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token boolean">true</span><span class="token punctuation">,</span><span class="token boolean">nil</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x5728; <code>startGarbageCollectorController</code> &#x4E2D;&#x4E3B;&#x8981;&#x8C03;&#x7528;&#x4E86;&#x56DB;&#x79CD;&#x65B9;&#x6CD5;<code>garbagecollector.NewGarbageCollector</code>&#x3001;<code>garbageCollector.Run</code>&#x3001;<code>garbageCollector.Sync</code> &#x548C; <code>garbagecollector.NewDebugHandler</code> &#x6765;&#x5B8C;&#x6210;&#x6838;&#x5FC3;&#x529F;&#x80FD;&#xFF0C;&#x4E0B;&#x9762;&#x4E3B;&#x8981;&#x9488;&#x5BF9;&#x8FD9;&#x56DB;&#x79CD;&#x65B9;&#x6CD5;&#x8FDB;&#x884C;&#x8BF4;&#x660E;&#x3002;</p>
<h4 id="garbagecollectornewgarbagecollector"><a name="garbagecollectornewgarbagecollector" class="anchor-navigation-ex-anchor" href="#garbagecollectornewgarbagecollector"><i class="fa fa-link" aria-hidden="true"></i></a>garbagecollector.NewGarbageCollector</h4>
<p><code>NewGarbageCollector</code> &#x7684;&#x4E3B;&#x8981;&#x529F;&#x80FD;&#x662F;&#x521D;&#x59CB;&#x5316; GarbageCollector &#x548C; GraphBuilder &#x5BF9;&#x8C61;&#xFF0C;&#x5E76;&#x8C03;&#x7528; <code>gb.syncMonitors</code>&#x65B9;&#x6CD5;&#x521D;&#x59CB;&#x5316; deletableResources &#x4E2D;&#x6240;&#x6709; resource controller &#x7684; informer&#x3002;GarbageCollector &#x7684;&#x4E3B;&#x8981;&#x4F5C;&#x7528;&#x662F;&#x542F;&#x52A8; GraphBuilder &#x4EE5;&#x53CA;&#x542F;&#x52A8;&#x6240;&#x6709;&#x7684;&#x6D88;&#x8D39;&#x8005;&#xFF0C;GraphBuilder &#x7684;&#x4E3B;&#x8981;&#x4F5C;&#x7528;&#x662F;&#x542F;&#x52A8;&#x6240;&#x6709;&#x7684;&#x751F;&#x4EA7;&#x8005;&#x3002;</p>
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token function">NewGarbageCollector</span><span class="token punctuation">(</span><span class="token operator">...</span><span class="token operator">...</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token operator">*</span>GarbageCollector<span class="token punctuation">,</span> <span class="token builtin">error</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
<span class="token operator">...</span><span class="token operator">...</span>
    gc <span class="token operator">:=</span><span class="token operator">&amp;</span>GarbageCollector<span class="token punctuation">{</span>
<span class="token operator">...</span><span class="token operator">...</span>
<span class="token punctuation">}</span>
    gb <span class="token operator">:=</span><span class="token operator">&amp;</span>GraphBuilder<span class="token punctuation">{</span>
<span class="token operator">...</span><span class="token operator">...</span>
<span class="token punctuation">}</span>
<span class="token keyword">if</span> err <span class="token operator">:=</span> gb<span class="token punctuation">.</span><span class="token function">syncMonitors</span><span class="token punctuation">(</span>deletableResources<span class="token punctuation">)</span><span class="token punctuation">;</span> err <span class="token operator">!=</span><span class="token boolean">nil</span><span class="token punctuation">{</span>
        utilruntime<span class="token punctuation">.</span><span class="token function">HandleError</span><span class="token punctuation">(</span>fmt<span class="token punctuation">.</span><span class="token function">Errorf</span><span class="token punctuation">(</span><span class="token string">&quot;failed to sync all monitors: %v&quot;</span><span class="token punctuation">,</span> err<span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>
    gc<span class="token punctuation">.</span>dependencyGraphBuilder <span class="token operator">=</span> gb
<span class="token keyword">return</span> gc<span class="token punctuation">,</span><span class="token boolean">nil</span>
<span class="token punctuation">}</span>
</code></pre>
<h5 id="gbsyncmonitors"><a name="gbsyncmonitors" class="anchor-navigation-ex-anchor" href="#gbsyncmonitors"><i class="fa fa-link" aria-hidden="true"></i></a>gb.syncMonitors</h5>
<p><code>syncMonitors</code> &#x7684;&#x4E3B;&#x8981;&#x4F5C;&#x7528;&#x662F;&#x521D;&#x59CB;&#x5316;&#x5404;&#x4E2A;&#x8D44;&#x6E90;&#x5BF9;&#x8C61;&#x7684; informer&#xFF0C;&#x5E76;&#x8C03;&#x7528; <code>gb.controllerFor</code> &#x4E3A;&#x6BCF;&#x79CD;&#x8D44;&#x6E90;&#x6CE8;&#x518C; eventHandler&#xFF0C;&#x6B64;&#x5904;&#x6BCF;&#x79CD;&#x8D44;&#x6E90;&#x88AB;&#x79F0;&#x4E3A; monitors&#xFF0C;&#x56E0;&#x4E3A;&#x4E3A;&#x6BCF;&#x79CD;&#x8D44;&#x6E90;&#x6CE8;&#x518C; eventHandler &#x65F6;&#xFF0C;&#x5BF9;&#x4E8E; AddFunc&#x3001;UpdateFunc &#x548C; DeleteFunc &#x90FD;&#x4F1A;&#x5C06;&#x5BF9;&#x5E94;&#x7684; event push &#x5230; graphChanges &#x961F;&#x5217;&#x4E2D;&#xFF0C;&#x6BCF;&#x79CD;&#x8D44;&#x6E90;&#x5BF9;&#x8C61;&#x7684; informer &#x90FD;&#x4F5C;&#x4E3A;&#x751F;&#x4EA7;&#x8005;&#x3002;</p>
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token punctuation">(</span>gb <span class="token operator">*</span>GraphBuilder<span class="token punctuation">)</span> <span class="token function">syncMonitors</span><span class="token punctuation">(</span>resources <span class="token keyword">map</span><span class="token punctuation">[</span>schema<span class="token punctuation">.</span>GroupVersionResource<span class="token punctuation">]</span><span class="token keyword">struct</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token builtin">error</span> <span class="token punctuation">{</span>
    gb<span class="token punctuation">.</span>monitorLock<span class="token punctuation">.</span><span class="token function">Lock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token keyword">defer</span> gb<span class="token punctuation">.</span>monitorLock<span class="token punctuation">.</span><span class="token function">Unlock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token operator">...</span><span class="token operator">...</span>
<span class="token keyword">for</span> resource <span class="token operator">:=</span> <span class="token keyword">range</span> resources <span class="token punctuation">{</span>
<span class="token keyword">if</span> <span class="token boolean">_</span><span class="token punctuation">,</span> ok <span class="token operator">:=</span> gb<span class="token punctuation">.</span>ignoredResources<span class="token punctuation">[</span>resource<span class="token punctuation">.</span><span class="token function">GroupResource</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">]</span><span class="token punctuation">;</span> ok <span class="token punctuation">{</span>
<span class="token keyword">continue</span>
<span class="token punctuation">}</span>
<span class="token operator">...</span><span class="token operator">...</span>
        kind<span class="token punctuation">,</span> err <span class="token operator">:=</span> gb<span class="token punctuation">.</span>restMapper<span class="token punctuation">.</span><span class="token function">KindFor</span><span class="token punctuation">(</span>resource<span class="token punctuation">)</span>
<span class="token keyword">if</span> err <span class="token operator">!=</span><span class="token boolean">nil</span><span class="token punctuation">{</span>
            errs <span class="token operator">=</span> <span class="token function">append</span><span class="token punctuation">(</span>errs<span class="token punctuation">,</span> fmt<span class="token punctuation">.</span><span class="token function">Errorf</span><span class="token punctuation">(</span><span class="token string">&quot;couldn&apos;t look up resource %q: %v&quot;</span><span class="token punctuation">,</span> resource<span class="token punctuation">,</span> err<span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token keyword">continue</span>
<span class="token punctuation">}</span>
<span class="token comment">// &#x4E3A; resource &#x7684; controller &#x6CE8;&#x518C; eventHandler </span>
        c<span class="token punctuation">,</span> s<span class="token punctuation">,</span> err <span class="token operator">:=</span> gb<span class="token punctuation">.</span><span class="token function">controllerFor</span><span class="token punctuation">(</span>resource<span class="token punctuation">,</span> kind<span class="token punctuation">)</span>
<span class="token keyword">if</span> err <span class="token operator">!=</span><span class="token boolean">nil</span><span class="token punctuation">{</span>
            errs <span class="token operator">=</span> <span class="token function">append</span><span class="token punctuation">(</span>errs<span class="token punctuation">,</span> fmt<span class="token punctuation">.</span><span class="token function">Errorf</span><span class="token punctuation">(</span><span class="token string">&quot;couldn&apos;t start monitor for resource %q: %v&quot;</span><span class="token punctuation">,</span> resource<span class="token punctuation">,</span> err<span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token keyword">continue</span>
<span class="token punctuation">}</span>
        current<span class="token punctuation">[</span>resource<span class="token punctuation">]</span><span class="token operator">=</span><span class="token operator">&amp;</span>monitor<span class="token punctuation">{</span>store<span class="token punctuation">:</span> s<span class="token punctuation">,</span> controller<span class="token punctuation">:</span> c<span class="token punctuation">}</span>
        added<span class="token operator">++</span>
<span class="token punctuation">}</span>
    gb<span class="token punctuation">.</span>monitors <span class="token operator">=</span> current
<span class="token keyword">for</span> <span class="token boolean">_</span><span class="token punctuation">,</span> monitor <span class="token operator">:=</span> <span class="token keyword">range</span> toRemove <span class="token punctuation">{</span>
<span class="token keyword">if</span> monitor<span class="token punctuation">.</span>stopCh <span class="token operator">!=</span><span class="token boolean">nil</span><span class="token punctuation">{</span>
            <span class="token function">close</span><span class="token punctuation">(</span>monitor<span class="token punctuation">.</span>stopCh<span class="token punctuation">)</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token keyword">return</span> utilerrors<span class="token punctuation">.</span><span class="token function">NewAggregate</span><span class="token punctuation">(</span>errs<span class="token punctuation">)</span>
<span class="token punctuation">}</span>
</code></pre>
<h6 id="gbcontrollerfor"><a name="gbcontrollerfor" class="anchor-navigation-ex-anchor" href="#gbcontrollerfor"><i class="fa fa-link" aria-hidden="true"></i></a>gb.controllerFor</h6>
<p>&#x5728; <code>gb.controllerFor</code>&#x4E2D;&#x4E3B;&#x8981;&#x662F;&#x4E3A;&#x6BCF;&#x4E2A; deletableResources &#x7684; informer &#x6CE8;&#x518C; eventHandler&#xFF0C;&#x6B64;&#x5904;&#x5C31;&#x53EF;&#x4EE5;&#x770B;&#x5230;&#x771F;&#x6B63;&#x7684;&#x751F;&#x4EA7;&#x8005;&#x4E86;&#x3002;</p>
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token punctuation">(</span>gb <span class="token operator">*</span>GraphBuilder<span class="token punctuation">)</span> <span class="token function">controllerFor</span><span class="token punctuation">(</span>resource schema<span class="token punctuation">.</span>GroupVersionResource<span class="token punctuation">,</span> kind schema<span class="token punctuation">.</span>GroupVersionKind<span class="token punctuation">)</span><span class="token punctuation">(</span>cache<span class="token punctuation">.</span>Controller<span class="token punctuation">,</span> cache<span class="token punctuation">.</span>Store<span class="token punctuation">,</span> <span class="token builtin">error</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    handlers <span class="token operator">:=</span> cache<span class="token punctuation">.</span>ResourceEventHandlerFuncs<span class="token punctuation">{</span>
AddFunc<span class="token punctuation">:</span> <span class="token keyword">func</span><span class="token punctuation">(</span>obj <span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
event<span class="token operator">:=</span><span class="token operator">&amp;</span>event<span class="token punctuation">{</span>
                eventType<span class="token punctuation">:</span> addEvent<span class="token punctuation">,</span>
                obj<span class="token punctuation">:</span>       obj<span class="token punctuation">,</span>
                gvk<span class="token punctuation">:</span>       kind<span class="token punctuation">,</span>
<span class="token punctuation">}</span>
<span class="token comment">// &#x5C06;&#x5BF9;&#x5E94;&#x7684; event push &#x5230; graphChanges &#x961F;&#x5217;&#x4E2D;</span>
            gb<span class="token punctuation">.</span>graphChanges<span class="token punctuation">.</span><span class="token function">Add</span><span class="token punctuation">(</span>event<span class="token punctuation">)</span>
<span class="token punctuation">}</span><span class="token punctuation">,</span>
UpdateFunc<span class="token punctuation">:</span> <span class="token keyword">func</span><span class="token punctuation">(</span>oldObj<span class="token punctuation">,</span> newObj <span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
event<span class="token operator">:=</span><span class="token operator">&amp;</span>event<span class="token punctuation">{</span>
                eventType<span class="token punctuation">:</span> updateEvent<span class="token punctuation">,</span>
                obj<span class="token punctuation">:</span>       newObj<span class="token punctuation">,</span>
                oldObj<span class="token punctuation">:</span>    oldObj<span class="token punctuation">,</span>
                gvk<span class="token punctuation">:</span>       kind<span class="token punctuation">,</span>
<span class="token punctuation">}</span>
<span class="token comment">// &#x5C06;&#x5BF9;&#x5E94;&#x7684; event push &#x5230; graphChanges &#x961F;&#x5217;&#x4E2D;</span>
            gb<span class="token punctuation">.</span>graphChanges<span class="token punctuation">.</span><span class="token function">Add</span><span class="token punctuation">(</span>event<span class="token punctuation">)</span>
<span class="token punctuation">}</span><span class="token punctuation">,</span>
DeleteFunc<span class="token punctuation">:</span> <span class="token keyword">func</span><span class="token punctuation">(</span>obj <span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
<span class="token keyword">if</span> deletedFinalStateUnknown<span class="token punctuation">,</span> ok <span class="token operator">:=</span> obj<span class="token punctuation">.</span><span class="token punctuation">(</span>cache<span class="token punctuation">.</span>DeletedFinalStateUnknown<span class="token punctuation">)</span><span class="token punctuation">;</span> ok <span class="token punctuation">{</span>
                obj <span class="token operator">=</span> deletedFinalStateUnknown<span class="token punctuation">.</span>Obj
<span class="token punctuation">}</span>
event<span class="token operator">:=</span><span class="token operator">&amp;</span>event<span class="token punctuation">{</span>
                eventType<span class="token punctuation">:</span> deleteEvent<span class="token punctuation">,</span>
                obj<span class="token punctuation">:</span>       obj<span class="token punctuation">,</span>
                gvk<span class="token punctuation">:</span>       kind<span class="token punctuation">,</span>
<span class="token punctuation">}</span>
<span class="token comment">// &#x5C06;&#x5BF9;&#x5E94;&#x7684; event push &#x5230; graphChanges &#x961F;&#x5217;&#x4E2D;</span>
            gb<span class="token punctuation">.</span>graphChanges<span class="token punctuation">.</span><span class="token function">Add</span><span class="token punctuation">(</span>event<span class="token punctuation">)</span>
<span class="token punctuation">}</span><span class="token punctuation">,</span>
<span class="token punctuation">}</span>
    shared<span class="token punctuation">,</span> err <span class="token operator">:=</span> gb<span class="token punctuation">.</span>sharedInformers<span class="token punctuation">.</span><span class="token function">ForResource</span><span class="token punctuation">(</span>resource<span class="token punctuation">)</span>
<span class="token keyword">if</span> err <span class="token operator">!=</span><span class="token boolean">nil</span><span class="token punctuation">{</span>
returnnil<span class="token punctuation">,</span><span class="token boolean">nil</span><span class="token punctuation">,</span> err
<span class="token punctuation">}</span>
    shared<span class="token punctuation">.</span><span class="token function">Informer</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">AddEventHandlerWithResyncPeriod</span><span class="token punctuation">(</span>handlers<span class="token punctuation">,</span>ResourceResyncTime<span class="token punctuation">)</span>
<span class="token keyword">return</span> shared<span class="token punctuation">.</span><span class="token function">Informer</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">GetController</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> shared<span class="token punctuation">.</span><span class="token function">Informer</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">GetStore</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token boolean">nil</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x81F3;&#x6B64; <code>NewGarbageCollector</code> &#x7684;&#x529F;&#x80FD;&#x5DF2;&#x7ECF;&#x5206;&#x6790;&#x5B8C;&#x4E86;&#xFF0C;&#x5728; <code>NewGarbageCollector</code> &#x4E2D;&#x521D;&#x59CB;&#x5316;&#x4E86;&#x4E24;&#x4E2A;&#x5BF9;&#x8C61; GarbageCollector &#x548C; GraphBuilder&#xFF0C;&#x7136;&#x540E;&#x5728; <code>gb.syncMonitors</code> &#x4E2D;&#x521D;&#x59CB;&#x5316;&#x4E86;&#x6240;&#x6709; deletableResources &#x7684; informer&#xFF0C;&#x4E3A;&#x6BCF;&#x4E2A; informer &#x6DFB;&#x52A0; eventHandler &#x5E76;&#x5C06;&#x76D1;&#x542C;&#x5230;&#x7684;&#x6240;&#x6709; event push &#x5230; graphChanges &#x961F;&#x5217;&#x4E2D;&#xFF0C;&#x6B64;&#x5904;&#x6BCF;&#x4E2A; informer &#x90FD;&#x88AB;&#x79F0;&#x4E3A; monitor&#xFF0C;&#x6240;&#x6709; informer &#x90FD;&#x88AB;&#x79F0;&#x4E3A;&#x751F;&#x4EA7;&#x8005;&#x3002;graphChanges &#x662F; GraphBuilder &#x4E2D;&#x7684;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#xFF0C;GraphBuilder &#x7684;&#x4E3B;&#x8981;&#x529F;&#x80FD;&#x662F;&#x4F5C;&#x4E3A;&#x4E00;&#x4E2A;&#x751F;&#x4EA7;&#x8005;&#xFF0C;&#x5176;&#x4F1A;&#x5904;&#x7406; graphChanges &#x4E2D;&#x7684;&#x6240;&#x6709;&#x4E8B;&#x4EF6;&#x5E76;&#x8FDB;&#x884C;&#x5206;&#x7C7B;&#xFF0C;&#x5C06;&#x4E8B;&#x4EF6;&#x653E;&#x5165;&#x5230; attemptToDelete &#x548C; attemptToOrphan &#x4E24;&#x4E2A;&#x961F;&#x5217;&#x4E2D;&#xFF0C;&#x5177;&#x4F53;&#x5904;&#x7406;&#x903B;&#x8F91;&#x4E0B;&#x6587;&#x8BB2;&#x8FF0;&#x3002;</p>
<p><code>NewGarbageCollector</code> &#x4E2D;&#x7684;&#x8C03;&#x7528;&#x903B;&#x8F91;&#x5982;&#x4E0B;&#x6240;&#x793A;&#xFF1A;</p>
<pre class="language-"><code>|--&gt; ctx.ClientBuilder.
|ClientOrDie
|
|
|--&gt; cacheddiscovery.
|NewMemCacheClient
||--&gt; gb.sharedInformers.
||ForResource
||
startGarbage     ----|--&gt; garbagecollector.--&gt; gb.syncMonitors --&gt; gb.controllerFor --|
CollectorController|NewGarbageCollector|
||
||--&gt; shared.Informer().
|AddEventHandlerWithResyncPeriod
|--&gt; garbageCollector.Run
|
|
|--&gt; garbageCollector.Sync
|
|
|--&gt; garbagecollector.NewDebugHandler
</code></pre><h4 id="garbagecollectorrun"><a name="garbagecollectorrun" class="anchor-navigation-ex-anchor" href="#garbagecollectorrun"><i class="fa fa-link" aria-hidden="true"></i></a>garbageCollector.Run</h4>
<p>&#x4E0A;&#x6587;&#x5DF2;&#x7ECF;&#x8BE6;&#x8FF0;&#x4E86; <code>NewGarbageCollector</code> &#x7684;&#x4E3B;&#x8981;&#x529F;&#x80FD;&#xFF0C;&#x7136;&#x540E;&#x7EE7;&#x7EED;&#x5206;&#x6790; <code>startGarbageCollectorController</code> &#x4E2D;&#x7684;&#x7B2C;&#x4E8C;&#x4E2A;&#x6838;&#x5FC3;&#x65B9;&#x6CD5; <code>garbageCollector.Run</code>&#xFF0C;<code>garbageCollector.Run</code> &#x7684;&#x4E3B;&#x8981;&#x4F5C;&#x7528;&#x662F;&#x542F;&#x52A8;&#x6240;&#x6709;&#x7684;&#x751F;&#x4EA7;&#x8005;&#x548C;&#x6D88;&#x8D39;&#x8005;&#xFF0C;&#x5176;&#x9996;&#x5148;&#x4F1A;&#x8C03;&#x7528; <code>gc.dependencyGraphBuilder.Run</code> &#x542F;&#x52A8;&#x6240;&#x6709;&#x7684;&#x751F;&#x4EA7;&#x8005;&#xFF0C;&#x5373; monitors&#xFF0C;&#x7136;&#x540E;&#x518D;&#x542F;&#x52A8;&#x4E00;&#x4E2A; goroutine &#x5904;&#x7406; graphChanges &#x961F;&#x5217;&#x4E2D;&#x7684;&#x4E8B;&#x4EF6;&#x5E76;&#x5206;&#x522B;&#x653E;&#x5230; attemptToDelete &#x548C; attemptToOrphan &#x4E24;&#x4E2A;&#x961F;&#x5217;&#x4E2D;&#xFF0C;dependencyGraphBuilder &#x5373;&#x4E0A;&#x6587;&#x63D0;&#x5230;&#x7684; GraphBuilder&#xFF0C;<code>run</code> &#x65B9;&#x6CD5;&#x4F1A;&#x8C03;&#x7528; <code>gc.runAttemptToDeleteWorker</code> &#x548C; <code>gc.runAttemptToOrphanWorker</code> &#x542F;&#x52A8;&#x591A;&#x4E2A; goroutine &#x5904;&#x7406; attemptToDelete &#x548C; attemptToOrphan &#x4E24;&#x4E2A;&#x961F;&#x5217;&#x4E2D;&#x7684;&#x4E8B;&#x4EF6;&#x3002;</p>
<pre class="language-"><code>func (gc *GarbageCollector)Run(workers int, stopCh &lt;-chan struct{}){
    defer utilruntime.HandleCrash()
    defer gc.attemptToDelete.ShutDown()
    defer gc.attemptToOrphan.ShutDown()
    defer gc.dependencyGraphBuilder.graphChanges.ShutDown()
    defer klog.Infof(&quot;Shutting down garbage collector controller&quot;)
// 1&#x3001;&#x8C03;&#x7528; gc.dependencyGraphBuilder.Run &#x542F;&#x52A8;&#x6240;&#x6709;&#x7684; monitors &#x5373; informers&#xFF0C;&#x5E76;&#x4E14;&#x542F;&#x52A8;&#x4E00;&#x4E2A; goroutine &#x5904;&#x7406; graphChanges &#x4E2D;&#x7684;&#x4E8B;&#x4EF6;&#x5C06;&#x5176;&#x5206;&#x522B;&#x653E;&#x5230; GraphBuilder &#x7684; attemptToDelete &#x548C; attemptToOrphan &#x4E24;&#x4E2A; &#x961F;&#x5217;&#x4E2D;&#xFF1B;
    go gc.dependencyGraphBuilder.Run(stopCh)
// 2&#x3001;&#x7B49;&#x5F85; informers &#x7684; cache &#x540C;&#x6B65;&#x5B8C;&#x6210;
if!cache.WaitForNamedCacheSync(&quot;garbage collector&quot;, stopCh, gc.dependencyGraphBuilder.IsSynced){
return
}
for i :=0; i &lt; workers; i++{
// 3&#x3001;&#x542F;&#x52A8;&#x591A;&#x4E2A; goroutine &#x8C03;&#x7528; gc.runAttemptToDeleteWorker &#x5904;&#x7406; attemptToDelete &#x4E2D;&#x7684;&#x4E8B;&#x4EF6;
        go wait.Until(gc.runAttemptToDeleteWorker,1*time.Second, stopCh)
// 4&#x3001;&#x542F;&#x52A8;&#x591A;&#x4E2A; goroutine &#x8C03;&#x7528; gc.runAttemptToOrphanWorker &#x5904;&#x7406; attemptToDelete &#x4E2D;&#x7684;&#x4E8B;&#x4EF6;
        go wait.Until(gc.runAttemptToOrphanWorker,1*time.Second, stopCh)
}
&lt;-stopCh
}
</code></pre><p><code>Run</code> &#x65B9;&#x6CD5;&#x4E2D;&#x8C03;&#x7528;&#x4E86; <code>gc.dependencyGraphBuilder.Run</code> &#x6765;&#x5B8C;&#x6210; GraphBuilder &#x7684;&#x542F;&#x52A8;&#x3002;</p>
<h5 id="gcdependencygraphbuilderrun"><a name="gcdependencygraphbuilderrun" class="anchor-navigation-ex-anchor" href="#gcdependencygraphbuilderrun"><i class="fa fa-link" aria-hidden="true"></i></a>gc.dependencyGraphBuilder.Run</h5>
<p>GraphBuilder &#x5728; garbageCollector &#x6574;&#x4E2A;&#x73AF;&#x8282;&#x4E2D;&#x8D77;&#x5230;&#x627F;&#x4E0A;&#x542F;&#x4E0B;&#x7684;&#x4F5C;&#x7528;&#xFF0C;&#x9996;&#x5148;&#x770B;&#x4E00;&#x4E0B; GraphBuilder &#x5BF9;&#x8C61;&#x7684;&#x7ED3;&#x6784;&#xFF1A;</p>
<pre class="language-"><code>type GraphBuilderstruct{
    restMapper meta.RESTMapper
// informers
    monitors    monitors
    monitorLock sync.RWMutex
// &#x5F53; kube-controller-manager &#x4E2D;&#x6240;&#x6709;&#x7684; controllers &#x90FD;&#x542F;&#x52A8;&#x540E;&#xFF0C;informersStarted &#x4F1A;&#x88AB; close &#x6389;
// informersStarted &#x4F1A;&#x88AB; close &#x6389;&#x7684;&#x8C03;&#x7528;&#x7A0B;&#x5E8F;&#x5728; kube-controller-manager &#x7684;&#x542F;&#x52A8;&#x6D41;&#x7A0B;&#x4E2D;
    informersStarted &lt;-chan struct{}
    stopCh &lt;-chan struct{}
// &#x5F53;&#x8C03;&#x7528; GraphBuilder &#x7684; run &#x65B9;&#x6CD5;&#x65F6;&#xFF0C;running &#x4F1A;&#x88AB;&#x8BBE;&#x7F6E;&#x4E3A; true
    running bool
    metadataClient metadata.Interface
// informers &#x76D1;&#x542C;&#x5230;&#x7684;&#x4E8B;&#x4EF6;&#x4F1A;&#x653E;&#x5728; graphChanges &#x4E2D;
    graphChanges workqueue.RateLimitingInterface
// &#x7EF4;&#x62A4;&#x6240;&#x6709;&#x5BF9;&#x8C61;&#x7684;&#x4F9D;&#x8D56;&#x5173;&#x7CFB; 
    uidToNode *concurrentUIDToNode
// GarbageCollector &#x4F5C;&#x4E3A;&#x6D88;&#x8D39;&#x8005;&#x8981;&#x5904;&#x7406; attemptToDelete &#x548C; attemptToOrphan &#x4E24;&#x4E2A;&#x961F;&#x5217;&#x4E2D;&#x7684;&#x4E8B;&#x4EF6;
    attemptToDelete workqueue.RateLimitingInterface
    attemptToOrphan workqueue.RateLimitingInterface
    absentOwnerCache *UIDCache
    sharedInformers  controller.InformerFactory
// &#x4E0D;&#x9700;&#x8981;&#x88AB; gc &#x7684;&#x8D44;&#x6E90;
    ignoredResources map[schema.GroupResource]struct{}
}
</code></pre><h6 id="uidtonode"><a name="uidtonode" class="anchor-navigation-ex-anchor" href="#uidtonode"><i class="fa fa-link" aria-hidden="true"></i></a>uidToNode</h6>
<p>&#x6B64;&#x5904;&#x6709;&#x5FC5;&#x8981;&#x5148;&#x8BF4;&#x660E;&#x4E00;&#x4E0B; uidToNode &#x7684;&#x529F;&#x80FD;&#xFF0C;uidToNode &#x6570;&#x636E;&#x7ED3;&#x6784;&#x4E2D;&#x7EF4;&#x62A4;&#x7740;&#x6240;&#x6709;&#x5BF9;&#x8C61;&#x7684;&#x4F9D;&#x8D56;&#x5173;&#x7CFB;&#xFF0C;&#x6B64;&#x5904;&#x7684;&#x4F9D;&#x8D56;&#x5173;&#x7CFB;&#x662F;&#x6307;&#x6BD4;&#x5982;&#x5F53;&#x521B;&#x5EFA;&#x4E00;&#x4E2A; deployment &#x65F6;&#x4F1A;&#x521B;&#x5EFA;&#x5BF9;&#x5E94;&#x7684; rs &#x4EE5;&#x53CA; pod&#xFF0C;pod &#x7684; owner &#x5C31;&#x662F; rs&#xFF0C;rs &#x7684; owner &#x662F; deployment&#xFF0C;rs &#x7684; dependents &#x662F;&#x5176;&#x5173;&#x8054;&#x7684;&#x6240;&#x6709; pod&#xFF0C;deployment &#x7684; dependents &#x662F;&#x5176;&#x5173;&#x8054;&#x7684;&#x6240;&#x6709; rs&#x3002;</p>
<p>uidToNode &#x4E2D;&#x7684; node &#x4E0D;&#x662F;&#x6307; k8s &#x4E2D;&#x7684; node &#x8282;&#x70B9;&#xFF0C;&#x800C;&#x662F;&#x5C06; graphChanges &#x4E2D;&#x7684; event &#x8F6C;&#x6362;&#x4E3A; node &#x5BF9;&#x8C61;&#xFF0C;k8s &#x4E2D;&#x6240;&#x6709; object &#x4E4B;&#x95F4;&#x7684;&#x7EA7;&#x8054;&#x5173;&#x7CFB;&#x662F;&#x901A;&#x8FC7; node &#x7684;&#x6982;&#x5FF5;&#x6765;&#x7EF4;&#x62A4;&#x7684;&#xFF0C;garbageCollector &#x5728;&#x540E;&#x7EED;&#x7684;&#x5904;&#x7406;&#x4E2D;&#x4F1A;&#x76F4;&#x63A5;&#x4F7F;&#x7528; node &#x5BF9;&#x8C61;&#xFF0C;node &#x5BF9;&#x8C61;&#x5B9A;&#x4E49;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre class="language-"><code>type concurrentUIDToNode struct {    uidToNodeLock sync.RWMutex    uidToNode     map[types.UID]*node}type node struct {    identity objectReference    dependentsLock sync.RWMutex    // &#x5176;&#x4F9D;&#x8D56;&#x9879;&#x6307; metadata.ownerReference &#x4E2D;&#x7684;&#x5BF9;&#x8C61;    dependents map[*node]struct{}    deletingDependents     bool    deletingDependentsLock sync.RWMutex    beingDeleted     bool    beingDeletedLock sync.RWMutex    // &#x5F53; virtual &#x503C;&#x4E3A; true &#x65F6;&#xFF0C;&#x6B64;&#x65F6;&#x4E0D;&#x786E;&#x5B9A;&#x8BE5;&#x5BF9;&#x8C61;&#x662F;&#x5426;&#x5B58;&#x5728;&#x4E8E; apiserver &#x4E2D;    virtual     bool    virtualLock sync.RWMutex    // &#x5BF9;&#x8C61;&#x672C;&#x8EAB;&#x7684; OwnerReference &#x5217;&#x8868;    owners []metav1.OwnerReference}
</code></pre><p>GraphBuilder &#x4E3B;&#x8981;&#x6709;&#x4E09;&#x4E2A;&#x529F;&#x80FD;&#xFF1A;</p>
<ul>
<li>1&#x3001;&#x76D1;&#x63A7;&#x96C6;&#x7FA4;&#x4E2D;&#x6240;&#x6709;&#x7684;&#x53EF;&#x5220;&#x9664;&#x8D44;&#x6E90;&#xFF1B;</li>
<li>2&#x3001;&#x57FA;&#x4E8E; informers &#x4E2D;&#x7684;&#x8D44;&#x6E90;&#x5728; uidToNode &#x6570;&#x636E;&#x7ED3;&#x6784;&#x4E2D;&#x7EF4;&#x62A4;&#x7740;&#x6240;&#x6709;&#x5BF9;&#x8C61;&#x7684;&#x4F9D;&#x8D56;&#x5173;&#x7CFB;&#xFF1B;</li>
<li>3&#x3001;&#x5904;&#x7406; graphChanges &#x4E2D;&#x7684;&#x4E8B;&#x4EF6;&#x5E76;&#x653E;&#x5230; attemptToDelete &#x548C; attemptToOrphan &#x4E24;&#x4E2A;&#x961F;&#x5217;&#x4E2D;&#xFF1B;</li>
</ul>
<p>&#x4E0A;&#x6587;&#x5DF2;&#x7ECF;&#x8BF4;&#x4E86; <code>gc.dependencyGraphBuilder.Run</code> &#x7684;&#x529F;&#x80FD;&#xFF0C;&#x542F;&#x52A8;&#x6240;&#x6709;&#x7684; informers &#x7136;&#x540E;&#x518D;&#x542F;&#x52A8;&#x4E00;&#x4E2A; goroutine &#x5904;&#x7406; graphChanges &#x961F;&#x5217;&#x4E2D;&#x7684;&#x4E8B;&#x4EF6;&#x5E76;&#x5206;&#x522B;&#x653E;&#x5230; attemptToDelete &#x548C; attemptToOrphan &#x4E24;&#x4E2A;&#x961F;&#x5217;&#x4E2D;&#xFF0C;&#x4EE3;&#x7801;&#x5982;&#x4E0B;&#x6240;&#x793A;&#xFF1A;</p>
<pre class="language-"><code>type concurrentUIDToNode struct{
    uidToNodeLock sync.RWMutex
    uidToNode     map[types.UID]*node
}
type node struct{
    identity objectReference
    dependentsLock sync.RWMutex
// &#x5176;&#x4F9D;&#x8D56;&#x9879;&#x6307; metadata.ownerReference &#x4E2D;&#x7684;&#x5BF9;&#x8C61;
    dependents map[*node]struct{}
    deletingDependents     bool
    deletingDependentsLock sync.RWMutex
    beingDeleted     bool
    beingDeletedLock sync.RWMutex
// &#x5F53; virtual &#x503C;&#x4E3A; true &#x65F6;&#xFF0C;&#x6B64;&#x65F6;&#x4E0D;&#x786E;&#x5B9A;&#x8BE5;&#x5BF9;&#x8C61;&#x662F;&#x5426;&#x5B58;&#x5728;&#x4E8E; apiserver &#x4E2D;
virtualbool
    virtualLock sync.RWMutex
// &#x5BF9;&#x8C61;&#x672C;&#x8EAB;&#x7684; OwnerReference &#x5217;&#x8868;
    owners []metav1.OwnerReference
}
</code></pre><p><code>gc.dependencyGraphBuilder.Run</code>&#x7684;&#x6838;&#x5FC3;&#x662F;&#x8C03;&#x7528;&#x4E86; <code>gb.startMonitors</code> &#x548C; <code>gb.runProcessGraphChanges</code> &#x4E24;&#x4E2A;&#x65B9;&#x6CD5;&#x6765;&#x5B8C;&#x6210;&#x4E3B;&#x8981;&#x529F;&#x80FD;&#xFF0C;&#x7EE7;&#x7EED;&#x770B;&#x8FD9;&#x4E24;&#x4E2A;&#x65B9;&#x6CD5;&#x7684;&#x4E3B;&#x8981;&#x903B;&#x8F91;&#x3002;</p>
<h6 id="gbstartmonitors"><a name="gbstartmonitors" class="anchor-navigation-ex-anchor" href="#gbstartmonitors"><i class="fa fa-link" aria-hidden="true"></i></a>gb.startMonitors</h6>
<p><code>startMonitors</code> &#x7684;&#x529F;&#x80FD;&#x5F88;&#x7B80;&#x5355;&#x5C31;&#x662F;&#x542F;&#x52A8;&#x6240;&#x6709;&#x7684; informers&#xFF0C;&#x4EE3;&#x7801;&#x5982;&#x4E0B;&#x6240;&#x793A;&#xFF1A;</p>
<pre class="language-"><code>func (gb *GraphBuilder)Run(stopCh &lt;-chan struct{}){
    klog.Infof(&quot;GraphBuilder running&quot;)
    defer klog.Infof(&quot;GraphBuilder stopping&quot;)
    gb.monitorLock.Lock()
    gb.stopCh = stopCh
    gb.running =true
    gb.monitorLock.Unlock()
    gb.startMonitors()
// &#x8C03;&#x7528; gb.runProcessGraphChanges
// &#x6B64;&#x5904;&#x4E3A;&#x6B7B;&#x5FAA;&#x73AF;&#xFF0C;&#x9664;&#x975E;&#x6536;&#x5230; stopCh &#x4FE1;&#x53F7;&#xFF0C;&#x5426;&#x5219;&#x4E0B;&#x9762;&#x7684;&#x4EE3;&#x7801;&#x4E0D;&#x4F1A;&#x88AB;&#x6267;&#x884C;&#x5230;
    wait.Until(gb.runProcessGraphChanges,1*time.Second, stopCh)
// &#x82E5;&#x6267;&#x884C;&#x5230;&#x6B64;&#x5904;&#x8BF4;&#x660E;&#x6536;&#x5230;&#x4E86; stopCh &#x7684;&#x4FE1;&#x53F7;&#xFF0C;&#x6B64;&#x65F6;&#x9700;&#x8981;&#x505C;&#x6B62;&#x6240;&#x6709;&#x7684; running monitors
    gb.monitorLock.Lock()
    defer gb.monitorLock.Unlock()
    monitors := gb.monitors
    stopped :=0
for _, monitor := range monitors {
if monitor.stopCh !=nil{
            stopped++
            close(monitor.stopCh)
}
}
    gb.monitors =nil
}
</code></pre><h6 id="gbrunprocessgraphchanges"><a name="gbrunprocessgraphchanges" class="anchor-navigation-ex-anchor" href="#gbrunprocessgraphchanges"><i class="fa fa-link" aria-hidden="true"></i></a>gb.runProcessGraphChanges</h6>
<p><code>runProcessGraphChanges</code> &#x65B9;&#x6CD5;&#x7684;&#x4E3B;&#x8981;&#x529F;&#x80FD;&#x662F;&#x5904;&#x7406; graphChanges &#x4E2D;&#x7684;&#x4E8B;&#x4EF6;&#x5C06;&#x5176;&#x5206;&#x522B;&#x653E;&#x5230; GraphBuilder &#x7684; attemptToDelete &#x548C; attemptToOrphan &#x4E24;&#x4E2A;&#x961F;&#x5217;&#x4E2D;&#xFF0C;&#x4EE3;&#x7801;&#x4E3B;&#x8981;&#x903B;&#x8F91;&#x4E3A;&#xFF1A;</p>
<ul>
<li><p>1&#x3001;&#x4ECE; graphChanges &#x961F;&#x5217;&#x4E2D;&#x53D6;&#x51FA;&#x4E00;&#x4E2A; item &#x5373; event&#xFF1B;</p>
</li>
<li><p>2&#x3001;&#x83B7;&#x53D6; event &#x7684; accessor&#xFF0C;accessor &#x662F;&#x4E00;&#x4E2A; object &#x7684; meta.Interface&#xFF0C;&#x91CC;&#x9762;&#x5305;&#x542B;&#x8BBF;&#x95EE; object meta &#x4E2D;&#x6240;&#x6709;&#x5B57;&#x6BB5;&#x7684;&#x65B9;&#x6CD5;&#xFF1B;</p>
</li>
<li><p>3&#x3001;&#x901A;&#x8FC7; accessor &#x83B7;&#x53D6; UID &#x5224;&#x65AD; uidToNode &#x4E2D;&#x662F;&#x5426;&#x5B58;&#x5728;&#x8BE5; object&#xFF1B;</p>
</li>
<li><p>4&#x3001;&#x82E5; uidToNode &#x4E2D;&#x4E0D;&#x5B58;&#x5728;&#x8BE5; node &#x4E14;&#x8BE5;&#x4E8B;&#x4EF6;&#x662F; addEvent &#x6216; updateEvent&#xFF0C;&#x5219;&#x4E3A;&#x8BE5; object &#x521B;&#x5EFA;&#x5BF9;&#x5E94;&#x7684; node&#xFF0C;&#x5E76;&#x8C03;&#x7528; <code>gb.insertNode</code> &#x5C06;&#x8BE5; node &#x52A0;&#x5230; uidToNode &#x4E2D;&#xFF0C;&#x7136;&#x540E;&#x5C06;&#x8BE5; node &#x6DFB;&#x52A0;&#x5230;&#x5176; owner &#x7684; dependents &#x4E2D;&#xFF0C;&#x6267;&#x884C;&#x5B8C; <code>gb.insertNode</code> &#x4E2D;&#x7684;&#x64CD;&#x4F5C;&#x540E;&#x518D;&#x8C03;&#x7528; <code>gb.processTransitions</code> &#x65B9;&#x6CD5;&#x5224;&#x65AD;&#x8BE5;&#x5BF9;&#x8C61;&#x662F;&#x5426;&#x5904;&#x4E8E;&#x5220;&#x9664;&#x72B6;&#x6001;&#xFF0C;&#x82E5;&#x5904;&#x4E8E;&#x5220;&#x9664;&#x72B6;&#x6001;&#x4F1A;&#x5224;&#x65AD;&#x8BE5;&#x5BF9;&#x8C61;&#x662F;&#x4EE5; <code>orphan</code> &#x6A21;&#x5F0F;&#x5220;&#x9664;&#x8FD8;&#x662F;&#x4EE5; <code>foreground</code> &#x6A21;&#x5F0F;&#x5220;&#x9664;&#xFF0C;&#x82E5;&#x4EE5; <code>orphan</code> &#x6A21;&#x5F0F;&#x5220;&#x9664;&#xFF0C;&#x5219;&#x5C06;&#x8BE5; node &#x52A0;&#x5165;&#x5230; attemptToOrphan &#x961F;&#x5217;&#x4E2D;&#xFF0C;&#x82E5;&#x4EE5; <code>foreground</code> &#x6A21;&#x5F0F;&#x5220;&#x9664;&#x5219;&#x5C06;&#x8BE5;&#x5BF9;&#x8C61;&#x4EE5;&#x53CA;&#x5176;&#x6240;&#x6709; dependents &#x90FD;&#x52A0;&#x5165;&#x5230; attemptToDelete &#x961F;&#x5217;&#x4E2D;&#xFF1B;</p>
</li>
<li><p>5&#x3001;&#x82E5; uidToNode &#x4E2D;&#x5B58;&#x5728;&#x8BE5; node &#x4E14;&#x8BE5;&#x4E8B;&#x4EF6;&#x662F; addEvent &#x6216; updateEvent &#x65F6;&#xFF0C;&#x6B64;&#x65F6;&#x53EF;&#x80FD;&#x662F;&#x4E00;&#x4E2A; update &#x64CD;&#x4F5C;&#xFF0C;&#x8C03;&#x7528; <code>referencesDiffs</code> &#x65B9;&#x6CD5;&#x68C0;&#x67E5;&#x8BE5;&#x5BF9;&#x8C61;&#x7684; <code>OwnerReferences</code> &#x5B57;&#x6BB5;&#x662F;&#x5426;&#x6709;&#x53D8;&#x5316;&#xFF0C;&#x82E5;&#x6709;&#x53D8;&#x5316;(1)&#x8C03;&#x7528; <code>gb.addUnblockedOwnersToDeleteQueue</code> &#x5C06;&#x88AB;&#x5220;&#x9664;&#x4EE5;&#x53CA;&#x66F4;&#x65B0;&#x7684; owner &#x5BF9;&#x5E94;&#x7684; node &#x52A0;&#x5165;&#x5230; attemptToDelete &#x4E2D;&#xFF0C;&#x56E0;&#x4E3A;&#x6B64;&#x65F6;&#x8BE5; node &#x4E2D;&#x5DF2;&#x88AB;&#x5220;&#x9664;&#x6216;&#x66F4;&#x65B0;&#x7684; owner &#x53EF;&#x80FD;&#x5904;&#x4E8E;&#x5220;&#x9664;&#x72B6;&#x6001;&#x4E14;&#x963B;&#x585E;&#x5728;&#x8BE5; node &#x5904;&#xFF0C;&#x6B64;&#x65F6;&#x6709;&#x4E09;&#x79CD;&#x65B9;&#x5F0F;&#x907F;&#x514D;&#x8BE5; node &#x7684; owner &#x5904;&#x4E8E;&#x5220;&#x9664;&#x963B;&#x585E;&#x72B6;&#x6001;&#xFF0C;&#x4E00;&#x662F;&#x7B49;&#x5F85;&#x8BE5; node &#x88AB;&#x5220;&#x9664;&#xFF0C;&#x4E8C;&#x662F;&#x5C06;&#x8BE5; node &#x81EA;&#x8EAB;&#x5BF9;&#x5E94; owner &#x7684; <code>OwnerReferences</code> &#x5B57;&#x6BB5;&#x5220;&#x9664;&#xFF0C;&#x4E09;&#x662F;&#x5C06;&#x8BE5; node <code>OwnerReferences</code> &#x5B57;&#x6BB5;&#x4E2D;&#x5BF9;&#x5E94; owner &#x7684; <code>BlockOwnerDeletion</code> &#x8BBE;&#x7F6E;&#x4E3A; false&#xFF1B;(2)&#x66F4;&#x65B0;&#x8BE5; node &#x7684; owners &#x5217;&#x8868;&#xFF1B;(3)&#x82E5;&#x6709;&#x65B0;&#x589E;&#x7684; owner&#xFF0C;&#x5C06;&#x8BE5; node &#x52A0;&#x5165;&#x5230;&#x65B0; owner &#x7684; dependents &#x4E2D;&#xFF1B;(4) &#x82E5;&#x6709;&#x88AB;&#x5220;&#x9664;&#x7684; owner&#xFF0C;&#x5C06;&#x8BE5; node &#x4ECE;&#x5DF2;&#x5220;&#x9664; owner &#x7684; dependents &#x4E2D;&#x5220;&#x9664;&#xFF1B;&#x4EE5;&#x4E0A;&#x64CD;&#x4F5C;&#x5B8C;&#x6210;&#x540E;&#xFF0C;&#x68C0;&#x67E5;&#x8BE5; node &#x662F;&#x5426;&#x5904;&#x4E8E;&#x5220;&#x9664;&#x72B6;&#x6001;&#x5E76;&#x8FDB;&#x884C;&#x6807;&#x8BB0;&#xFF0C;&#x6700;&#x540E;&#x8C03;&#x7528; <code>gb.processTransitions</code> &#x65B9;&#x6CD5;&#x68C0;&#x67E5;&#x8BE5; node &#x662F;&#x5426;&#x8981;&#x88AB;&#x5220;&#x9664;&#xFF1B;</p>
<p>&#x4E3E;&#x4E2A;&#x4F8B;&#x5B50;&#xFF0C;&#x82E5;&#x4EE5; <code>foreground</code> &#x6A21;&#x5F0F;&#x5220;&#x9664; deployment &#x65F6;&#xFF0C;deployment &#x7684; dependents &#x5217;&#x8868;&#x4E2D;&#x6709;&#x5BF9;&#x5E94;&#x7684; rs&#xFF0C;&#x90A3;&#x4E48; deployment &#x7684;&#x5220;&#x9664;&#x4F1A;&#x963B;&#x585E;&#x4F4F;&#x7B49;&#x5F85;&#x5176;&#x4F9D;&#x8D56; rs &#x7684;&#x5220;&#x9664;&#xFF0C;&#x6B64;&#x65F6; rs &#x6709;&#x4E09;&#x79CD;&#x65B9;&#x6CD5;&#x4E0D;&#x963B;&#x585E; deployment &#x7684;&#x5220;&#x9664;&#x64CD;&#x4F5C;&#xFF0C;&#x4E00;&#x662F; rs &#x5BF9;&#x8C61;&#x88AB;&#x5220;&#x9664;&#xFF0C;&#x4E8C;&#x662F;&#x5220;&#x9664; rs &#x5BF9;&#x8C61; <code>OwnerReferences</code> &#x5B57;&#x6BB5;&#x4E2D;&#x5BF9;&#x5E94;&#x7684; deployment&#xFF0C;&#x4E09;&#x662F;&#x5C06; rs &#x5BF9;&#x8C61;<code>OwnerReferences</code> &#x5B57;&#x6BB5;&#x4E2D;&#x5BF9;&#x5E94;&#x7684; deployment &#x914D;&#x7F6E; <code>BlockOwnerDeletion</code> &#x8BBE;&#x7F6E;&#x4E3A; false&#xFF0C;&#x6587;&#x672B;&#x4F1A;&#x6709;&#x793A;&#x4F8B;&#x6F14;&#x793A;&#x8BE5;&#x64CD;&#x4F5C;&#x3002;</p>
</li>
<li><p>6&#x3001;&#x82E5;&#x8BE5;&#x4E8B;&#x4EF6;&#x4E3A; deleteEvent&#xFF0C;&#x9996;&#x5148;&#x4ECE; uidToNode &#x4E2D;&#x5220;&#x9664;&#x8BE5;&#x5BF9;&#x8C61;&#xFF0C;&#x7136;&#x540E;&#x4ECE;&#x8BE5; node &#x6240;&#x6709; owners &#x7684; dependents &#x4E2D;&#x5220;&#x9664;&#x8BE5;&#x5BF9;&#x8C61;&#xFF0C;&#x5C06;&#x8BE5; node &#x6240;&#x6709;&#x7684; dependents &#x52A0;&#x5165;&#x5230; attemptToDelete &#x961F;&#x5217;&#x4E2D;&#xFF0C;&#x6700;&#x540E;&#x68C0;&#x67E5;&#x8BE5; node &#x7684;&#x6240;&#x6709; owners&#xFF0C;&#x82E5;&#x6709;&#x5904;&#x4E8E;&#x5220;&#x9664;&#x72B6;&#x6001;&#x7684; owner&#xFF0C;&#x6B64;&#x65F6;&#x8BE5; owner &#x53EF;&#x80FD;&#x5904;&#x4E8E;&#x5220;&#x9664;&#x963B;&#x585E;&#x72B6;&#x6001;&#x6B63;&#x5728;&#x7B49;&#x5F85;&#x8BE5; node &#x7684;&#x5220;&#x9664;&#xFF0C;&#x5C06;&#x8BE5; owner &#x52A0;&#x5165;&#x5230; attemptToDelete &#x4E2D;&#xFF1B;</p>
</li>
</ul>
<p>&#x603B;&#x7ED3;&#x4E00;&#x4E0B;&#xFF0C;&#x5F53;&#x4ECE; graphChanges &#x4E2D;&#x53D6;&#x51FA; event &#x65F6;&#xFF0C;&#x4E0D;&#x7BA1;&#x662F;&#x4EC0;&#x4E48; event&#xFF0C;&#x4E3B;&#x8981;&#x5B8C;&#x6210;&#x4E09;&#x4EF6;&#x65F6;&#xFF0C;&#x9996;&#x5148;&#x90FD;&#x4F1A;&#x5C06; event &#x8F6C;&#x5316;&#x4E3A; uidToNode &#x4E2D;&#x7684; node &#x5BF9;&#x8C61;&#xFF0C;&#x5176;&#x6B21;&#x4E00;&#x662F;&#x66F4;&#x65B0; uidToNode &#x4E2D;&#x7EF4;&#x62A4;&#x7684;&#x4F9D;&#x8D56;&#x5173;&#x7CFB;&#xFF0C;&#x4E8C;&#x662F;&#x66F4;&#x65B0;&#x8BE5; node &#x7684; owners &#x4EE5;&#x53CA; owners &#x7684; dependents&#xFF0C;&#x4E09;&#x662F;&#x68C0;&#x67E5;&#x8BE5; node &#x7684; owners &#x662F;&#x5426;&#x8981;&#x88AB;&#x5220;&#x9664;&#x4EE5;&#x53CA;&#x8BE5; node &#x7684; dependents &#x662F;&#x5426;&#x8981;&#x88AB;&#x5220;&#x9664;&#xFF0C;&#x82E5;&#x9700;&#x8981;&#x5220;&#x9664;&#x5219;&#x6839;&#x636E; node &#x7684;&#x5220;&#x9664;&#x7B56;&#x7565;&#x5C06;&#x5176;&#x6DFB;&#x52A0;&#x5230; attemptToOrphan &#x6216;&#x8005; attemptToDelete &#x961F;&#x5217;&#x4E2D;&#xFF1B;</p>
<pre class="language-"><code>func (gb *GraphBuilder) runProcessGraphChanges(){
for gb.processGraphChanges(){
}
}
func (gb *GraphBuilder) processGraphChanges()bool{
// 1&#x3001;&#x4ECE; graphChanges &#x53D6;&#x51FA;&#x4E00;&#x4E2A; event
    item, quit := gb.graphChanges.Get()
if quit {
returnfalse
}
    defer gb.graphChanges.Done(item)
event, ok := item.(*event)
if!ok {
        utilruntime.HandleError(fmt.Errorf(&quot;expect a *event, got %v&quot;, item))
returntrue
}
    obj :=event.obj
    accessor, err := meta.Accessor(obj)
if err !=nil{
        utilruntime.HandleError(fmt.Errorf(&quot;cannot access obj: %v&quot;, err))
returntrue
}
// 2&#x3001;&#x82E5;&#x5B58;&#x5728; node &#x5BF9;&#x8C61;&#xFF0C;&#x4ECE; uidToNode &#x4E2D;&#x53D6;&#x51FA;&#x8BE5; event &#x7684; node &#x5BF9;&#x8C61;
    existingNode, found := gb.uidToNode.Read(accessor.GetUID())
if found {
        existingNode.markObserved()
}
switch{
// 3&#x3001;&#x82E5; event &#x4E3A; add &#x6216; update &#x7C7B;&#x578B;&#x4EE5;&#x53CA;&#x5BF9;&#x5E94;&#x7684; node &#x5BF9;&#x8C61;&#x4E0D;&#x5B58;&#x5728;&#x65F6;
case(event.eventType == addEvent ||event.eventType == updateEvent)&amp;&amp;!found:
// 4&#x3001;&#x4E3A; node &#x521B;&#x5EFA; event &#x5BF9;&#x8C61;
        newNode :=&amp;node{
......
}
// 5&#x3001;&#x5728; uidToNode &#x4E2D;&#x6DFB;&#x52A0;&#x8BE5; node &#x5BF9;&#x8C61;
        gb.insertNode(newNode)
// 6&#x3001;&#x68C0;&#x67E5;&#x5E76;&#x5904;&#x7406; node &#x7684;&#x5220;&#x9664;&#x64CD;&#x4F5C; 
        gb.processTransitions(event.oldObj, accessor, newNode)
// 7&#x3001;&#x82E5; event &#x4E3A; add &#x6216; update &#x7C7B;&#x578B;&#x4EE5;&#x53CA;&#x5BF9;&#x5E94;&#x7684; node &#x5BF9;&#x8C61;&#x5B58;&#x5728;&#x65F6;
case(event.eventType == addEvent ||event.eventType == updateEvent)&amp;&amp; found:
        added, removed, changed := referencesDiffs(existingNode.owners, accessor.GetOwnerReferences())
// 8&#x3001;&#x82E5; node &#x7684; owners &#x6709;&#x53D8;&#x5316;
if len(added)!=0|| len(removed)!=0|| len(changed)!=0{
            gb.addUnblockedOwnersToDeleteQueue(removed, changed)
// 9&#x3001;&#x66F4;&#x65B0; uidToNode &#x4E2D;&#x7684; owners
            existingNode.owners = accessor.GetOwnerReferences()
// 10&#x3001;&#x6DFB;&#x52A0;&#x66F4;&#x65B0;&#x540E; Owners &#x5BF9;&#x5E94;&#x7684; dependent
            gb.addDependentToOwners(existingNode, added)
// 11&#x3001;&#x79FB;&#x9664;&#x65E7; owners &#x5BF9;&#x5E94;&#x7684; dependents
            gb.removeDependentFromOwners(existingNode, removed)
}
// 12&#x3001;&#x68C0;&#x67E5;&#x662F;&#x5426;&#x5904;&#x4E8E;&#x5220;&#x9664;&#x72B6;&#x6001;
if beingDeleted(accessor){
            existingNode.markBeingDeleted()
}
// 13&#x3001;&#x68C0;&#x67E5;&#x5E76;&#x5904;&#x7406; node &#x7684;&#x5220;&#x9664;&#x64CD;&#x4F5C; 
        gb.processTransitions(event.oldObj, accessor, existingNode)
// 14&#x3001;&#x82E5;&#x4E3A; delete event
caseevent.eventType == deleteEvent:
if!found {
returntrue
}
// 15&#x3001;&#x4ECE; uidToNode &#x4E2D;&#x5220;&#x9664;&#x8BE5; node
        gb.removeNode(existingNode)
        existingNode.dependentsLock.RLock()
        defer existingNode.dependentsLock.RUnlock()
if len(existingNode.dependents)&gt;0{
            gb.absentOwnerCache.Add(accessor.GetUID())
}
// 16&#x3001;&#x5220;&#x9664;&#x8BE5; node &#x7684; dependents
for dep := range existingNode.dependents {
            gb.attemptToDelete.Add(dep)
}
// 17&#x3001;&#x5220;&#x9664;&#x8BE5; node &#x5904;&#x4E8E;&#x5220;&#x9664;&#x963B;&#x585E;&#x72B6;&#x6001;&#x7684; owner 
for _, owner := range existingNode.owners {
            ownerNode, found := gb.uidToNode.Read(owner.UID)
if!found ||!ownerNode.isDeletingDependents(){
continue
}
            gb.attemptToDelete.Add(ownerNode)
}
}
returntrue
}
</code></pre><h6 id="processtransitions"><a name="processtransitions" class="anchor-navigation-ex-anchor" href="#processtransitions"><i class="fa fa-link" aria-hidden="true"></i></a>processTransitions</h6>
<p>&#x4E0A;&#x8FF0;&#x5728;&#x5904;&#x7406; add &#x6216; update event &#x65F6;&#x6700;&#x540E;&#x90FD;&#x8C03;&#x7528;&#x4E86; <code>processTransitions</code> &#x65B9;&#x6CD5;&#x68C0;&#x67E5; node &#x662F;&#x5426;&#x5904;&#x4E8E;&#x5220;&#x9664;&#x72B6;&#x6001;&#xFF0C;&#x82E5;&#x5904;&#x4E8E;&#x5220;&#x9664;&#x72B6;&#x6001;&#x4F1A;&#x901A;&#x8FC7;&#x5176;&#x5220;&#x9664;&#x7B56;&#x7565;&#x5C06; node &#x653E;&#x5230; attemptToOrphan &#x6216; attemptToDelete &#x961F;&#x5217;&#x4E2D;&#x3002;</p>
<pre class="language-"><code>k8s.io/kubernetes/pkg/controller/garbagecollector/graph_builder.go:509
func (gb *GraphBuilder) processTransitions(oldObj interface{}, newAccessor metav1.Object, n *node) {    if startsWaitingForDependentsOrphaned(oldObj, newAccessor) {        gb.attemptToOrphan.Add(n)        return    }    if startsWaitingForDependentsDeleted(oldObj, newAccessor) {        n.markDeletingDependents()        for dep := range n.dependents {            gb.attemptToDelete.Add(dep)        }        gb.attemptToDelete.Add(n)    }}
</code></pre><h5 id="gcrunattempttodeleteworker"><a name="gcrunattempttodeleteworker" class="anchor-navigation-ex-anchor" href="#gcrunattempttodeleteworker"><i class="fa fa-link" aria-hidden="true"></i></a>gc.runAttemptToDeleteWorker</h5>
<p><code>runAttemptToDeleteWorker</code> &#x662F;&#x6267;&#x884C;&#x5220;&#x9664; attemptToDelete &#x4E2D; node &#x7684;&#x65B9;&#x6CD5;&#xFF0C;&#x5176;&#x4E3B;&#x8981;&#x903B;&#x8F91;&#x4E3A;&#xFF1A;</p>
<ul>
<li>1&#x3001;&#x8C03;&#x7528; <code>gc.attemptToDeleteItem</code> &#x5220;&#x9664; node&#xFF1B;</li>
<li>2&#x3001;&#x82E5;&#x5220;&#x9664;&#x5931;&#x8D25;&#x5219;&#x91CD;&#x65B0;&#x52A0;&#x5165;&#x5230; attemptToDelete &#x961F;&#x5217;&#x4E2D;&#x8FDB;&#x884C;&#x91CD;&#x8BD5;&#xFF1B;</li>
</ul>
<pre class="language-"><code>k8s.io/kubernetes/pkg/controller/garbagecollector/garbagecollector.go:280
func (gc *GarbageCollector) runAttemptToDeleteWorker() {    for gc.attemptToDeleteWorker() {    }}func (gc *GarbageCollector) attemptToDeleteWorker() bool {    item, quit := gc.attemptToDelete.Get()    gc.workerLock.RLock()    defer gc.workerLock.RUnlock()    if quit {        return false    }    defer gc.attemptToDelete.Done(item)    n, ok := item.(*node)    if !ok {        utilruntime.HandleError(fmt.Errorf(&quot;expect *node, got %#v&quot;, item))        return true    }    err := gc.attemptToDeleteItem(n)    if err != nil {        if _, ok := err.(*restMappingError); ok {            klog.V(5).Infof(&quot;error syncing item %s: %v&quot;, n, err)        } else {            utilruntime.HandleError(fmt.Errorf(&quot;error syncing item %s: %v&quot;, n, err))        }        gc.attemptToDelete.AddRateLimited(item)    } else if !n.isObserved() {        gc.attemptToDelete.AddRateLimited(item)    }    return true}
</code></pre><p><code>gc.runAttemptToDeleteWorker</code> &#x4E2D;&#x8C03;&#x7528;&#x4E86; <code>gc.attemptToDeleteItem</code> &#x6267;&#x884C;&#x5B9E;&#x9645;&#x7684;&#x5220;&#x9664;&#x64CD;&#x4F5C;&#x3002;</p>
<h6 id="gcattempttodeleteitem"><a name="gcattempttodeleteitem" class="anchor-navigation-ex-anchor" href="#gcattempttodeleteitem"><i class="fa fa-link" aria-hidden="true"></i></a>gc.attemptToDeleteItem</h6>
<p><code>gc.attemptToDeleteItem</code> &#x7684;&#x4E3B;&#x8981;&#x903B;&#x8F91;&#x4E3A;&#xFF1A;</p>
<ul>
<li><p>1&#x3001;&#x5224;&#x65AD; node &#x662F;&#x5426;&#x5904;&#x4E8E;&#x5220;&#x9664;&#x72B6;&#x6001;&#xFF1B;</p>
</li>
<li><p>2&#x3001;&#x4ECE; apiserver &#x83B7;&#x53D6;&#x8BE5; node &#x6700;&#x65B0;&#x7684;&#x72B6;&#x6001;&#xFF0C;&#x8BE5; node &#x53EF;&#x80FD;&#x4E3A; virtual node&#xFF0C;&#x82E5;&#x4E3A; virtual node &#x5219;&#x4ECE; apiserver &#x4E2D;&#x83B7;&#x53D6;&#x4E0D;&#x5230;&#x8BE5; node &#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x6B64;&#x65F6;&#x4F1A;&#x5C06;&#x8BE5; node &#x91CD;&#x65B0;&#x52A0;&#x5165;&#x5230; graphChanges &#x961F;&#x5217;&#x4E2D;&#xFF0C;&#x518D;&#x6B21;&#x5904;&#x7406;&#x8BE5; node &#x65F6;&#x4F1A;&#x5C06;&#x5176;&#x4ECE; uidToNode &#x4E2D;&#x5220;&#x9664;&#xFF1B;</p>
</li>
<li><p>3&#x3001;&#x5224;&#x65AD;&#x8BE5; node &#x6700;&#x65B0;&#x72B6;&#x6001;&#x7684; uid &#x662F;&#x5426;&#x7B49;&#x4E8E;&#x672C;&#x5730;&#x7F13;&#x5B58;&#x4E2D;&#x7684; uid&#xFF0C;&#x82E5;&#x4E0D;&#x5339;&#x914D;&#x8BF4;&#x660E;&#x8BE5; node &#x5DF2;&#x66F4;&#x65B0;&#x8FC7;&#x6B64;&#x65F6;&#x5C06;&#x5176;&#x8BBE;&#x7F6E;&#x4E3A; virtual node &#x5E76;&#x91CD;&#x65B0;&#x52A0;&#x5165;&#x5230; graphChanges &#x961F;&#x5217;&#x4E2D;&#xFF0C;&#x518D;&#x6B21;&#x5904;&#x7406;&#x8BE5; node &#x65F6;&#x4F1A;&#x5C06;&#x5176;&#x4ECE; uidToNode &#x4E2D;&#x5220;&#x9664;&#xFF1B;</p>
</li>
<li><p>4&#x3001;&#x901A;&#x8FC7; node &#x7684; <code>deletingDependents</code> &#x5B57;&#x6BB5;&#x5224;&#x65AD;&#x8BE5; node &#x5F53;&#x524D;&#x662F;&#x5426;&#x5904;&#x4E8E;&#x5220;&#x9664; dependents &#x7684;&#x72B6;&#x6001;&#xFF0C;&#x82E5;&#x8BE5; node &#x5904;&#x4E8E;&#x5220;&#x9664; dependents &#x7684;&#x72B6;&#x6001;&#x5219;&#x8C03;&#x7528; <code>processDeletingDependentsItem</code> &#x65B9;&#x6CD5;&#x68C0;&#x67E5; node &#x7684; <code>blockingDependents</code> &#x662F;&#x5426;&#x88AB;&#x5B8C;&#x5168;&#x5220;&#x9664;&#xFF0C;&#x82E5; <code>blockingDependents</code> &#x5DF2;&#x5B8C;&#x5168;&#x88AB;&#x5220;&#x9664;&#x5219;&#x5220;&#x9664;&#x8BE5; node &#x5BF9;&#x5E94;&#x7684; finalizer&#xFF0C;&#x82E5; <code>blockingDependents</code> &#x8FD8;&#x672A;&#x5220;&#x9664;&#x5B8C;&#xFF0C;&#x5C06;&#x672A;&#x5220;&#x9664;&#x7684; <code>blockingDependents</code> &#x52A0;&#x5165;&#x5230; attemptToDelete &#x4E2D;&#xFF1B;</p>
<p>&#x4E0A;&#x6587;&#x4E2D;&#x5728; GraphBuilder &#x5904;&#x7406; graphChanges &#x4E2D;&#x7684;&#x4E8B;&#x4EF6;&#x65F6;&#xFF0C;&#x82E5;&#x53D1;&#x73B0; node &#x5904;&#x4E8E;&#x5220;&#x9664;&#x72B6;&#x6001;&#xFF0C;&#x4F1A;&#x5C06; node &#x7684; dependents &#x52A0;&#x5165;&#x5230; attemptToDelete &#x4E2D;&#x5E76;&#x6807;&#x8BB0; node &#x7684; <code>deletingDependents</code> &#x4E3A; true&#xFF1B;</p>
</li>
<li><p>5&#x3001;&#x8C03;&#x7528; <code>gc.classifyReferences</code> &#x5C06; node &#x7684; <code>ownerReferences</code> &#x5206;&#x7C7B;&#x4E3A; <code>solid</code>, <code>dangling</code>, <code>waitingForDependentsDeletion</code> &#x4E09;&#x7C7B;&#xFF1A;<code>dangling</code>(owner &#x4E0D;&#x5B58;&#x5728;)&#x3001;<code>waitingForDependentsDeletion</code>(owner &#x5B58;&#x5728;&#xFF0C;owner &#x5904;&#x4E8E;&#x5220;&#x9664;&#x72B6;&#x6001;&#x4E14;&#x6B63;&#x5728;&#x7B49;&#x5F85;&#x5176; dependents &#x88AB;&#x5220;&#x9664;)&#x3001;<code>solid</code>(&#x81F3;&#x5C11;&#x6709;&#x4E00;&#x4E2A; owner &#x5B58;&#x5728;&#x4E14;&#x4E0D;&#x5904;&#x4E8E;&#x5220;&#x9664;&#x72B6;&#x6001;)&#xFF1B;</p>
</li>
<li><p>6&#x3001;&#x5BF9;&#x4EE5;&#x4E0A;&#x5206;&#x7C7B;&#x8FDB;&#x884C;&#x4E0D;&#x540C;&#x7684;&#x5904;&#x7406;&#xFF0C;&#x82E5; <code>solid</code>&#x4E0D;&#x4E3A; 0 &#x5373;&#x5F53;&#x524D; node &#x81F3;&#x5C11;&#x5B58;&#x5728;&#x4E00;&#x4E2A; owner&#xFF0C;&#x8BE5;&#x5BF9;&#x8C61;&#x8FD8;&#x4E0D;&#x80FD;&#x88AB;&#x56DE;&#x6536;&#xFF0C;&#x6B64;&#x65F6;&#x9700;&#x8981;&#x5C06; <code>dangling</code> &#x548C; <code>waitingForDependentsDeletion</code> &#x5217;&#x8868;&#x4E2D;&#x7684; owner &#x4ECE; node &#x7684; <code>ownerReferences</code> &#x5220;&#x9664;&#xFF0C;&#x5373;&#x5DF2;&#x7ECF;&#x88AB;&#x5220;&#x9664;&#x6216;&#x7B49;&#x5F85;&#x5220;&#x9664;&#x7684;&#x5F15;&#x7528;&#x4ECE;&#x5BF9;&#x8C61;&#x4E2D;&#x5220;&#x6389;&#xFF1B;</p>
</li>
<li><p>7&#x3001;&#x7B2C;&#x4E8C;&#x79CD;&#x60C5;&#x51B5;&#x662F;&#x8BE5; node &#x7684; owner &#x5904;&#x4E8E; <code>waitingForDependentsDeletion</code> &#x72B6;&#x6001;&#x5E76;&#x4E14; node &#x7684; dependents &#x672A;&#x88AB;&#x5B8C;&#x5168;&#x5220;&#x9664;&#xFF0C;&#x8BE5; node &#x9700;&#x8981;&#x7B49;&#x5F85;&#x5220;&#x9664;&#x5B8C;&#x6240;&#x6709;&#x7684; dependents &#x540E;&#x624D;&#x80FD;&#x88AB;&#x5220;&#x9664;&#xFF1B;</p>
</li>
<li><p>8&#x3001;&#x7B2C;&#x4E09;&#x79CD;&#x60C5;&#x51B5;&#x5C31;&#x662F;&#x8BE5; node &#x5DF2;&#x7ECF;&#x6CA1;&#x6709;&#x4EFB;&#x4F55; dependents &#x4E86;&#xFF0C;&#x6B64;&#x65F6;&#x6309;&#x7167; node &#x4E2D;&#x58F0;&#x660E;&#x7684;&#x5220;&#x9664;&#x7B56;&#x7565;&#x8C03;&#x7528; apiserver &#x7684;&#x63A5;&#x53E3;&#x5220;&#x9664;&#x5373;&#x53EF;&#xFF1B;</p>
</li>
</ul>
<pre class="language-"><code>k8s.io/kubernetes/pkg/controller/garbagecollector/garbagecollector.go:404
func (gc *GarbageCollector) attemptToDeleteItem(item *node) error {    // 1&#x3001;&#x5224;&#x65AD; node &#x662F;&#x5426;&#x5904;&#x4E8E;&#x5220;&#x9664;&#x72B6;&#x6001;    if item.isBeingDeleted() &amp;&amp; !item.isDeletingDependents() {        return nil    }    // 2&#x3001;&#x4ECE; apiserver &#x83B7;&#x53D6;&#x8BE5; node &#x6700;&#x65B0;&#x7684;&#x72B6;&#x6001;    latest, err := gc.getObject(item.identity)    switch {    case errors.IsNotFound(err):        gc.dependencyGraphBuilder.enqueueVirtualDeleteEvent(item.identity)        item.markObserved()        return nil    case err != nil:        return err    }    // 3&#x3001;&#x5224;&#x65AD;&#x8BE5; node &#x6700;&#x65B0;&#x72B6;&#x6001;&#x7684; uid &#x662F;&#x5426;&#x7B49;&#x4E8E;&#x672C;&#x5730;&#x7F13;&#x5B58;&#x4E2D;&#x7684; uid    if latest.GetUID() != item.identity.UID {        gc.dependencyGraphBuilder.enqueueVirtualDeleteEvent(item.identity)        item.markObserved()        return nil    }    // 4&#x3001;&#x5224;&#x65AD;&#x8BE5; node &#x5F53;&#x524D;&#x662F;&#x5426;&#x5904;&#x4E8E;&#x5220;&#x9664; dependents &#x72B6;&#x6001;&#x4E2D;    if item.isDeletingDependents() {        return gc.processDeletingDependentsItem(item)    }    // 5&#x3001;&#x68C0;&#x67E5; node &#x662F;&#x5426;&#x8FD8;&#x5B58;&#x5728; ownerReferences    ownerReferences := latest.GetOwnerReferences()    if len(ownerReferences) == 0 {        return nil    }    // 6&#x3001;&#x5BF9; ownerReferences &#x8FDB;&#x884C;&#x5206;&#x7C7B;    solid, dangling, waitingForDependentsDeletion, err := gc.classifyReferences(item, ownerReferences)    if err != nil {        return err    }    switch {    // 7&#x3001;&#x5B58;&#x5728;&#x4E0D;&#x5904;&#x4E8E;&#x5220;&#x9664;&#x72B6;&#x6001;&#x7684; owner    case len(solid) != 0:        if len(dangling) == 0 &amp;&amp; len(waitingForDependentsDeletion) == 0 {            return nil        }        ownerUIDs := append(ownerRefsToUIDs(dangling), ownerRefsToUIDs(waitingForDependentsDeletion)...)        patch := deleteOwnerRefStrategicMergePatch(item.identity.UID, ownerUIDs...)        _, err = gc.patch(item, patch, func(n *node) ([]byte, error) {            return gc.deleteOwnerRefJSONMergePatch(n, ownerUIDs...)        })        return err    // 8&#x3001;node &#x7684; owner &#x5904;&#x4E8E; waitingForDependentsDeletion &#x72B6;&#x6001;&#x5E76;&#x4E14; node     //   &#x7684; dependents &#x672A;&#x88AB;&#x5B8C;&#x5168;&#x5220;&#x9664;    case len(waitingForDependentsDeletion) != 0 &amp;&amp; item.dependentsLength() != 0:        deps := item.getDependents()        // 9&#x3001;&#x5220;&#x9664; dependents        for _, dep := range deps {            if dep.isDeletingDependents() {                patch, err := item.unblockOwnerReferencesStrategicMergePatch()                if err != nil {                    return err                }                if _, err := gc.patch(item, patch, gc.unblockOwnerReferencesJSONMergePatch); err != nil {                    return err                }                break            }        }        // 10&#x3001;&#x4EE5; Foreground &#x6A21;&#x5F0F;&#x5220;&#x9664; node &#x5BF9;&#x8C61;        policy := metav1.DeletePropagationForeground        return gc.deleteObject(item.identity, &amp;policy)    // 11&#x3001;&#x8BE5; node &#x5DF2;&#x7ECF;&#x6CA1;&#x6709;&#x4EFB;&#x4F55;&#x4F9D;&#x8D56;&#x4E86;&#xFF0C;&#x6309;&#x7167; node &#x4E2D;&#x58F0;&#x660E;&#x7684;&#x5220;&#x9664;&#x7B56;&#x7565;&#x8C03;&#x7528; apiserver &#x7684;&#x63A5;&#x53E3;&#x5220;&#x9664;    default:        var policy metav1.DeletionPropagation        switch {        case hasOrphanFinalizer(latest):            policy = metav1.DeletePropagationOrphan        case hasDeleteDependentsFinalizer(latest):            policy = metav1.DeletePropagationForeground        default:            policy = metav1.DeletePropagationBackground        }        return gc.deleteObject(item.identity, &amp;policy)    }}
</code></pre><h5 id="gcrunattempttoorphanworker"><a name="gcrunattempttoorphanworker" class="anchor-navigation-ex-anchor" href="#gcrunattempttoorphanworker"><i class="fa fa-link" aria-hidden="true"></i></a>gc.runAttemptToOrphanWorker</h5>
<p><code>runAttemptToOrphanWorker</code> &#x662F;&#x5904;&#x7406;&#x4EE5; <code>orphan</code> &#x6A21;&#x5F0F;&#x5220;&#x9664;&#x7684; node&#xFF0C;&#x4E3B;&#x8981;&#x903B;&#x8F91;&#x4E3A;&#xFF1A;</p>
<ul>
<li>1&#x3001;&#x8C03;&#x7528; <code>gc.orphanDependents</code> &#x5220;&#x9664; owner &#x6240;&#x6709; dependents <code>OwnerReferences</code> &#x4E2D;&#x7684; owner &#x5B57;&#x6BB5;&#xFF1B;</li>
<li>2&#x3001;&#x8C03;&#x7528; <code>gc.removeFinalizer</code> &#x5220;&#x9664; owner &#x7684; <code>orphan</code> Finalizer&#xFF1B;</li>
<li>3&#x3001;&#x4EE5;&#x4E0A;&#x4E24;&#x6B65;&#x4E2D;&#x82E5;&#x6709;&#x5931;&#x8D25;&#x7684;&#x4F1A;&#x8FDB;&#x884C;&#x91CD;&#x8BD5;&#xFF1B;</li>
</ul>
<pre class="language-"><code>k8s.io/kubernetes/pkg/controller/garbagecollector/garbagecollector.go:574
func (gc *GarbageCollector) runAttemptToOrphanWorker() {    for gc.attemptToOrphanWorker() {    }}func (gc *GarbageCollector) attemptToOrphanWorker() bool {    item, quit := gc.attemptToOrphan.Get()    gc.workerLock.RLock()    defer gc.workerLock.RUnlock()    if quit {        return false    }    defer gc.attemptToOrphan.Done(item)    owner, ok := item.(*node)    if !ok {        return true    }    owner.dependentsLock.RLock()    dependents := make([]*node, 0, len(owner.dependents))    for dependent := range owner.dependents {        dependents = append(dependents, dependent)    }    owner.dependentsLock.RUnlock()    err := gc.orphanDependents(owner.identity, dependents)    if err != nil {        gc.attemptToOrphan.AddRateLimited(item)        return true    }    // &#x66F4;&#x65B0; owner, &#x4ECE; finalizers &#x5217;&#x8868;&#x4E2D;&#x79FB;&#x9664; &quot;orphaningFinalizer&quot;    err = gc.removeFinalizer(owner, metav1.FinalizerOrphanDependents)    if err != nil {        gc.attemptToOrphan.AddRateLimited(item)    }    return true}
</code></pre><h4 id="garbagecollectorsync"><a name="garbagecollectorsync" class="anchor-navigation-ex-anchor" href="#garbagecollectorsync"><i class="fa fa-link" aria-hidden="true"></i></a>garbageCollector.Sync</h4>
<p><code>garbageCollector.Sync</code> &#x662F; <code>startGarbageCollectorController</code> &#x4E2D;&#x7684;&#x7B2C;&#x4E09;&#x4E2A;&#x6838;&#x5FC3;&#x65B9;&#x6CD5;&#xFF0C;&#x4E3B;&#x8981;&#x529F;&#x80FD;&#x662F;&#x5468;&#x671F;&#x6027;&#x7684;&#x67E5;&#x8BE2;&#x96C6;&#x7FA4;&#x4E2D;&#x6240;&#x6709;&#x7684;&#x8D44;&#x6E90;&#xFF0C;&#x8FC7;&#x6EE4;&#x51FA; <code>deletableResources</code>&#xFF0C;&#x7136;&#x540E;&#x5BF9;&#x6BD4;&#x5DF2;&#x7ECF;&#x76D1;&#x63A7;&#x7684; <code>deletableResources</code> &#x548C;&#x5F53;&#x524D;&#x83B7;&#x53D6;&#x5230;&#x7684; <code>deletableResources</code> &#x662F;&#x5426;&#x4E00;&#x81F4;&#xFF0C;&#x82E5;&#x4E0D;&#x4E00;&#x81F4;&#x5219;&#x66F4;&#x65B0; GraphBuilder &#x7684; monitors &#x5E76;&#x91CD;&#x65B0;&#x542F;&#x52A8; monitors &#x76D1;&#x63A7;&#x6240;&#x6709;&#x7684; <code>deletableResources</code>&#xFF0C;&#x8BE5;&#x65B9;&#x6CD5;&#x7684;&#x4E3B;&#x8981;&#x903B;&#x8F91;&#x4E3A;&#xFF1A;</p>
<ul>
<li>1&#x3001;&#x901A;&#x8FC7;&#x8C03;&#x7528; <code>GetDeletableResources</code> &#x83B7;&#x53D6;&#x96C6;&#x7FA4;&#x5185;&#x6240;&#x6709;&#x7684; <code>deletableResources</code> &#x4F5C;&#x4E3A; newResources&#xFF0C;<code>deletableResources</code> &#x6307;&#x652F;&#x6301; &#x201C;delete&#x201D;, &#x201C;list&#x201D;, &#x201C;watch&#x201D; &#x4E09;&#x79CD;&#x64CD;&#x4F5C;&#x7684; resource&#xFF0C;&#x5305;&#x62EC; CR&#xFF1B;</li>
<li>2&#x3001;&#x68C0;&#x67E5; oldResources, newResources &#x662F;&#x5426;&#x4E00;&#x81F4;&#xFF0C;&#x4E0D;&#x4E00;&#x81F4;&#x5219;&#x9700;&#x8981;&#x540C;&#x6B65;&#xFF1B;</li>
<li>3&#x3001;&#x8C03;&#x7528; <code>gc.resyncMonitors</code> &#x540C;&#x6B65; newResources&#xFF0C;&#x5728; <code>gc.resyncMonitors</code> &#x4E2D;&#x4F1A;&#x91CD;&#x65B0;&#x8C03;&#x7528; GraphBuilder &#x7684; <code>syncMonitors</code> &#x548C; <code>startMonitors</code> &#x4E24;&#x4E2A;&#x65B9;&#x6CD5;&#x5B8C;&#x6210; monitors &#x7684;&#x5237;&#x65B0;&#xFF1B;</li>
<li>4&#x3001;&#x7B49;&#x5F85; newResources informer &#x4E2D;&#x7684; cache &#x540C;&#x6B65;&#x5B8C;&#x6210;&#xFF1B;</li>
<li>5&#x3001;&#x5C06; newResources &#x4F5C;&#x4E3A; oldResources&#xFF0C;&#x7EE7;&#x7EED;&#x8FDB;&#x884C;&#x4E0B;&#x4E00;&#x8F6E;&#x7684;&#x540C;&#x6B65;&#xFF1B;</li>
</ul>
<pre class="language-"><code>k8s.io/kubernetes/pkg/controller/garbagecollector/garbagecollector.go:164
func (gc *GarbageCollector) Sync(discoveryClient discovery.ServerResourcesInterface, period time.Duration, stopCh &lt;-chan struct{}) {    oldResources := make(map[schema.GroupVersionResource]struct{})    wait.Until(func() {        // 1&#x3001;&#x83B7;&#x53D6;&#x96C6;&#x7FA4;&#x5185;&#x6240;&#x6709;&#x7684; DeletableResources &#x4F5C;&#x4E3A; newResources        newResources := GetDeletableResources(discoveryClient)        if len(newResources) == 0 {            return        }        // 2&#x3001;&#x5224;&#x65AD;&#x96C6;&#x7FA4;&#x4E2D;&#x7684;&#x8D44;&#x6E90;&#x662F;&#x5426;&#x6709;&#x53D8;&#x5316;        if reflect.DeepEqual(oldResources, newResources) {            return        }        gc.workerLock.Lock()        defer gc.workerLock.Unlock()        // 3&#x3001;&#x5F00;&#x59CB;&#x66F4;&#x65B0; GraphBuilder &#x4E2D;&#x7684; monitors              attempt := 0        wait.PollImmediateUntil(100*time.Millisecond, func() (bool, error) {            attempt++            if attempt &gt; 1 {                newResources = GetDeletableResources(discoveryClient)                if len(newResources) == 0 {                    return false, nil                }            }            gc.restMapper.Reset()            // 4&#x3001;&#x8C03;&#x7528; gc.resyncMonitors &#x540C;&#x6B65; newResources            if err := gc.resyncMonitors(newResources); err != nil {                return false, nil            }            // 5&#x3001;&#x7B49;&#x5F85;&#x6240;&#x6709; monitors &#x7684; cache &#x540C;&#x6B65;&#x5B8C;&#x6210;            if !cache.WaitForNamedCacheSync(&quot;garbage collector&quot;, waitForStopOrTimeout(stopCh, period), gc.dependencyGraphBuilder.IsSynced) {                return false, nil            }            return true, nil        }, stopCh)        // 6&#x3001;&#x66F4;&#x65B0; oldResources        oldResources = newResources    }, period, stopCh)}
</code></pre><p><code>garbageCollector.Sync</code> &#x4E2D;&#x4E3B;&#x8981;&#x8C03;&#x7528;&#x4E86;&#x4E24;&#x4E2A;&#x65B9;&#x6CD5;&#xFF0C;&#x4E00;&#x662F;&#x8C03;&#x7528; <code>GetDeletableResources</code> &#x83B7;&#x53D6;&#x96C6;&#x7FA4;&#x4E2D;&#x6240;&#x6709;&#x7684;&#x53EF;&#x5220;&#x9664;&#x8D44;&#x6E90;&#xFF0C;&#x4E8C;&#x662F;&#x8C03;&#x7528; <code>gc.resyncMonitors</code> &#x66F4;&#x65B0; GraphBuilder &#x4E2D; monitors&#x3002;</p>
<h5 id="getdeletableresources"><a name="getdeletableresources" class="anchor-navigation-ex-anchor" href="#getdeletableresources"><i class="fa fa-link" aria-hidden="true"></i></a>GetDeletableResources</h5>
<p>&#x5728; <code>GetDeletableResources</code> &#x4E2D;&#x9996;&#x5148;&#x901A;&#x8FC7;&#x8C03;&#x7528; <code>discoveryClient.ServerPreferredResources</code> &#x65B9;&#x6CD5;&#x83B7;&#x53D6;&#x96C6;&#x7FA4;&#x5185;&#x6240;&#x6709;&#x7684; resource &#x4FE1;&#x606F;&#xFF0C;&#x7136;&#x540E;&#x901A;&#x8FC7;&#x8C03;&#x7528; <code>discovery.FilteredBy</code> &#x8FC7;&#x6EE4;&#x51FA;&#x652F;&#x6301; &#x201C;delete&#x201D;, &#x201C;list&#x201D;, &#x201C;watch&#x201D; &#x4E09;&#x79CD;&#x65B9;&#x6CD5;&#x7684; resource &#x4F5C;&#x4E3A; <code>deletableResources</code>&#x3002;</p>
<pre class="language-"><code>k8s.io/kubernetes/pkg/controller/garbagecollector/garbagecollector.go:636
func GetDeletableResources(discoveryClient discovery.ServerResourcesInterface) map[schema.GroupVersionResource]struct{} {    // 1&#x3001;&#x8C03;&#x7528; discoveryClient.ServerPreferredResources &#x65B9;&#x6CD5;&#x83B7;&#x53D6;&#x96C6;&#x7FA4;&#x5185;&#x6240;&#x6709;&#x7684; resource &#x4FE1;&#x606F;    preferredResources, err := discoveryClient.ServerPreferredResources()    if err != nil {        if discovery.IsGroupDiscoveryFailedError(err) {                    ......        } else {            ......        }    }    if preferredResources == nil {        return map[schema.GroupVersionResource]struct{}{}    }    // 2&#x3001;&#x8C03;&#x7528; discovery.FilteredBy &#x8FC7;&#x6EE4;&#x51FA; deletableResources    deletableResources := discovery.FilteredBy(discovery.SupportsAllVerbs{Verbs: []string{&quot;delete&quot;, &quot;list&quot;, &quot;watch&quot;}}, preferredResources)    deletableGroupVersionResources := map[schema.GroupVersionResource]struct{}{}    for _, rl := range deletableResources {        gv, err := schema.ParseGroupVersion(rl.GroupVersion)        if err != nil {            continue        }        for i := range rl.APIResources {            deletableGroupVersionResources[schema.GroupVersionResource{Group: gv.Group, Version: gv.Version, Resource: rl.APIResources[i].Name}] =       struct{}{}        }    }    return deletableGroupVersionResources}
</code></pre><h6 id="serverpreferredresources"><a name="serverpreferredresources" class="anchor-navigation-ex-anchor" href="#serverpreferredresources"><i class="fa fa-link" aria-hidden="true"></i></a>ServerPreferredResources</h6>
<p><code>ServerPreferredResources</code> &#x7684;&#x4E3B;&#x8981;&#x529F;&#x80FD;&#x662F;&#x83B7;&#x53D6;&#x96C6;&#x7FA4;&#x5185;&#x6240;&#x6709;&#x7684; resource &#x4EE5;&#x53CA;&#x5176; group&#x3001;version&#x3001;verbs &#x4FE1;&#x606F;&#xFF0C;&#x8BE5;&#x65B9;&#x6CD5;&#x7684;&#x4E3B;&#x8981;&#x903B;&#x8F91;&#x4E3A;&#xFF1A;</p>
<ul>
<li>1&#x3001;&#x8C03;&#x7528; <code>ServerGroups</code> &#x65B9;&#x6CD5;&#x83B7;&#x53D6;&#x96C6;&#x7FA4;&#x5185;&#x6240;&#x6709;&#x7684; GroupList&#xFF0C;<code>ServerGroups</code> &#x65B9;&#x6CD5;&#x9996;&#x5148;&#x4ECE; apiserver &#x901A;&#x8FC7; <code>/api</code> URL &#x83B7;&#x53D6;&#x5F53;&#x524D;&#x7248;&#x672C;&#x4E0B;&#x6240;&#x6709;&#x53EF;&#x7528;&#x7684; <code>APIVersions</code>&#xFF0C;&#x518D;&#x901A;&#x8FC7; <code>/apis</code> URL &#x83B7;&#x53D6; &#x6240;&#x6709;&#x53EF;&#x7528;&#x7684; <code>APIVersions</code> &#x4EE5;&#x53CA;&#x5176;&#x4E0B;&#x7684;&#x6240;&#x6709; <code>APIGroupList</code>&#xFF1B;</li>
<li>2&#x3001;&#x8C03;&#x7528; <code>fetchGroupVersionResources</code> &#x901A;&#x8FC7; serverGroupList &#x518D;&#x83B7;&#x53D6;&#x5230;&#x5BF9;&#x5E94;&#x7684; resource&#xFF1B;</li>
<li>3&#x3001;&#x5C06;&#x83B7;&#x53D6;&#x5230;&#x7684; version&#x3001;group&#x3001;resource &#x6784;&#x5EFA;&#x6210;&#x6807;&#x51C6;&#x683C;&#x5F0F;&#x6DFB;&#x52A0;&#x5230; <code>metav1.APIResourceList</code> &#x4E2D;&#xFF1B;</li>
</ul>
<pre class="language-"><code>k8s.io/kubernetes/staging/src/k8s.io/client-go/discovery/discovery_client.go:285
func ServerPreferredResources(d DiscoveryInterface) ([]*metav1.APIResourceList, error) {    // 1&#x3001;&#x83B7;&#x53D6;&#x96C6;&#x7FA4;&#x5185;&#x6240;&#x6709;&#x7684; GroupList    serverGroupList, err := d.ServerGroups()    if err != nil {        return nil, err    }    // 2&#x3001;&#x901A;&#x8FC7; serverGroupList &#x83B7;&#x53D6;&#x5230;&#x5BF9;&#x5E94;&#x7684; resource    groupVersionResources, failedGroups := fetchGroupVersionResources(d, serverGroupList)    result := []*metav1.APIResourceList{}    grVersions := map[schema.GroupResource]string{}                         // selected version of a GroupResource    grAPIResources := map[schema.GroupResource]*metav1.APIResource{}        // selected APIResource for a GroupResource    gvAPIResourceLists := map[schema.GroupVersion]*metav1.APIResourceList{} // blueprint for a APIResourceList for later grouping    // 3&#x3001;&#x683C;&#x5F0F;&#x5316; resource     for _, apiGroup := range serverGroupList.Groups {        for _, version := range apiGroup.Versions {            groupVersion := schema.GroupVersion{Group: apiGroup.Name, Version: version.Version}            apiResourceList, ok := groupVersionResources[groupVersion]            if !ok {                continue            }            emptyAPIResourceList := metav1.APIResourceList{                GroupVersion: version.GroupVersion,            }            gvAPIResourceLists[groupVersion] = &amp;emptyAPIResourceList            result = append(result, &amp;emptyAPIResourceList)            for i := range apiResourceList.APIResources {                apiResource := &amp;apiResourceList.APIResources[i]                if strings.Contains(apiResource.Name, &quot;/&quot;) {                    continue                }                gv := schema.GroupResource{Group: apiGroup.Name, Resource: apiResource.Name}                if _, ok := grAPIResources[gv]; ok &amp;&amp; version.Version != apiGroup.PreferredVersion.Version {                    continue                }                grVersions[gv] = version.Version                grAPIResources[gv] = apiResource            }        }    }    for groupResource, apiResource := range grAPIResources {        version := grVersions[groupResource]        groupVersion := schema.GroupVersion{Group: groupResource.Group, Version: version}        apiResourceList := gvAPIResourceLists[groupVersion]        apiResourceList.APIResources = append(apiResourceList.APIResources, *apiResource)    }    if len(failedGroups) == 0 {        return result, nil    }    return result, &amp;ErrGroupDiscoveryFailed{Groups: failedGroups}}
</code></pre><p><code>GetDeletableResources</code> &#x65B9;&#x6CD5;&#x4E2D;&#x7684;&#x8C03;&#x7528;&#x6D41;&#x7A0B;&#x4E3A;&#xFF1A;</p>
<pre class="language-"><code>                                                      |--&gt; d.ServerGroups                                                      |                        |--&gt; discoveryClient.       --|                        |  ServerPreferredResources   |                        |                             |--&gt; fetchGroupVersionResourcesGetDeletableResources --|                        |                        |--&gt; discovery.FilteredBy
</code></pre><h5 id="gcresyncmonitors"><a name="gcresyncmonitors" class="anchor-navigation-ex-anchor" href="#gcresyncmonitors"><i class="fa fa-link" aria-hidden="true"></i></a>gc.resyncMonitors</h5>
<p><code>gc.resyncMonitors</code> &#x7684;&#x4E3B;&#x8981;&#x529F;&#x80FD;&#x662F;&#x66F4;&#x65B0; GraphBuilder &#x7684; monitors &#x5E76;&#x91CD;&#x65B0;&#x542F;&#x52A8; monitors &#x76D1;&#x63A7;&#x6240;&#x6709;&#x7684; deletableResources&#xFF0C;GraphBuilder &#x7684; <code>syncMonitors</code> &#x548C; <code>startMonitors</code> &#x65B9;&#x6CD5;&#x5728;&#x524D;&#x9762;&#x7684;&#x6D41;&#x7A0B;&#x4E2D;&#x5DF2;&#x7ECF;&#x5206;&#x6790;&#x8FC7;&#xFF0C;&#x6B64;&#x5904;&#x4E0D;&#x518D;&#x8BE6;&#x7EC6;&#x8BF4;&#x660E;&#x3002;</p>
<pre class="language-"><code>k8s.io/kubernetes/pkg/controller/garbagecollector/garbagecollector.go:116
func (gc *GarbageCollector) resyncMonitors(deletableResources map[schema.                          GroupVersionResource]struct{}) error {    if err := gc.dependencyGraphBuilder.syncMonitors(deletableResources); err != nil {        return err    }    gc.dependencyGraphBuilder.startMonitors()    return nil}
</code></pre><h4 id="garbagecollectornewdebughandler"><a name="garbagecollectornewdebughandler" class="anchor-navigation-ex-anchor" href="#garbagecollectornewdebughandler"><i class="fa fa-link" aria-hidden="true"></i></a>garbagecollector.NewDebugHandler</h4>
<p><code>garbagecollector.NewDebugHandler</code> &#x4E3B;&#x8981;&#x529F;&#x80FD;&#x662F;&#x5BF9;&#x5916;&#x63D0;&#x4F9B;&#x4E00;&#x4E2A;&#x63A5;&#x53E3;&#x4F9B;&#x7528;&#x6237;&#x67E5;&#x8BE2;&#x5F53;&#x524D;&#x96C6;&#x7FA4;&#x4E2D;&#x6240;&#x6709;&#x8D44;&#x6E90;&#x7684;&#x4F9D;&#x8D56;&#x5173;&#x7CFB;&#xFF0C;&#x4F9D;&#x8D56;&#x5173;&#x7CFB;&#x53EF;&#x4EE5;&#x4EE5;&#x56FE;&#x8868;&#x7684;&#x5F62;&#x5F0F;&#x5C55;&#x793A;&#x3002;</p>
<pre class="language-"><code>func startGarbageCollectorController(ctx ControllerContext) (http.Handler, bool, error) {    ......    return garbagecollector.NewDebugHandler(garbageCollector), true, nil}
</code></pre><p>&#x5177;&#x4F53;&#x4F7F;&#x7528;&#x65B9;&#x6CD5;&#x5982;&#x4E0B;&#x6240;&#x793A;&#xFF1A;</p>
<pre class="language-"><code>$ curl http://192.168.99.108:10252/debug/controllers/garbagecollector/graph  &gt; tmp.dot$ curl http://192.168.99.108:10252/debug/controllers/garbagecollector/graph\?uid=f9555d53-2b5f-4702-9717-54a313ed4fe8 &gt; tmp.dot// &#x751F;&#x6210; svg &#x6587;&#x4EF6;$ dot -Tsvg -o graph.svg tmp.dot// &#x7136;&#x540E;&#x5728;&#x6D4F;&#x89C8;&#x5668;&#x4E2D;&#x6253;&#x5F00; svg &#x6587;&#x4EF6;
</code></pre><p>&#x4F9D;&#x8D56;&#x5173;&#x7CFB;&#x56FE;&#x5982;&#x4E0B;&#x6240;&#x793A;&#xFF1A;</p>
<p><img src="https://static.sitestack.cn/projects/source-code-reading-notes/fe29b8fd2e0c4d30c8ec9159829d4e92.png" alt="garbage collector controller &#x6E90;&#x7801;&#x5206;&#x6790; - &#x56FE;1"></p>
<h3 id="&#x793A;&#x4F8B;"><a name="&#x793A;&#x4F8B;" class="anchor-navigation-ex-anchor" href="#&#x793A;&#x4F8B;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x793A;&#x4F8B;</h3>
<p>&#x5728;&#x6B64;&#x5904;&#x4F1A;&#x6709;&#x4E00;&#x4E2A;&#x5C0F;&#x793A;&#x4F8B;&#x9A8C;&#x8BC1;&#x4E00;&#x4E0B;&#x6E90;&#x7801;&#x4E2D;&#x7684;&#x5220;&#x9664;&#x963B;&#x585E;&#x903B;&#x8F91;&#xFF0C;&#x5F53;&#x4EE5; <code>Foreground</code> &#x7B56;&#x7565;&#x5220;&#x9664;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x65F6;&#xFF0C;&#x8BE5;&#x5BF9;&#x8C61;&#x4F1A;&#x5904;&#x4E8E;&#x963B;&#x585E;&#x72B6;&#x6001;&#x7B49;&#x5F85;&#x5176;&#x4F9D;&#x4F9D;&#x8D56;&#x88AB;&#x5220;&#x9664;&#xFF0C;&#x6B64;&#x65F6;&#x6709;&#x4E09;&#x79CD;&#x65B9;&#x5F0F;&#x907F;&#x514D;&#x8BE5;&#x5BF9;&#x8C61;&#x5904;&#x4E8E;&#x5220;&#x9664;&#x963B;&#x585E;&#x72B6;&#x6001;&#xFF0C;&#x4E00;&#x662F;&#x5C06;&#x4F9D;&#x8D56;&#x5BF9;&#x8C61;&#x76F4;&#x63A5;&#x5220;&#x9664;&#xFF0C;&#x4E8C;&#x662F;&#x5C06;&#x4F9D;&#x8D56;&#x5BF9;&#x8C61;&#x81EA;&#x8EAB;&#x7684; <code>OwnerReferences</code> &#x4E2D; owner &#x5B57;&#x6BB5;&#x5220;&#x9664;&#xFF0C;&#x4E09;&#x662F;&#x5C06;&#x8BE5;&#x4F9D;&#x8D56;&#x5BF9;&#x8C61; <code>OwnerReferences</code> &#x5B57;&#x6BB5;&#x4E2D;&#x5BF9;&#x5E94; owner &#x7684; <code>BlockOwnerDeletion</code> &#x8BBE;&#x7F6E;&#x4E3A; false&#xFF0C;&#x4E0B;&#x9762;&#x4F1A;&#x9A8C;&#x8BC1;&#x4E0B;&#x8FD9;&#x4E09;&#x79CD;&#x65B9;&#x5F0F;&#xFF0C;&#x9996;&#x5148;&#x521B;&#x5EFA;&#x4E00;&#x4E2A; deployment&#xFF0C;deployment &#x521B;&#x5EFA;&#x51FA;&#x7684; rs &#x9ED8;&#x8BA4;&#x4E0D;&#x4F1A;&#x6709; <code>foregroundDeletion finalizers</code>&#xFF0C;&#x6B64;&#x65F6;&#x4F7F;&#x7528; kubectl edit &#x624B;&#x52A8;&#x52A0;&#x4E0A; <code>foregroundDeletion finalizers</code>&#xFF0C;&#x5F53; deployment &#x6B63;&#x5E38;&#x8FD0;&#x884C;&#x65F6;&#xFF0C;&#x5982;&#x4E0B;&#x6240;&#x793A;&#xFF1A;</p>
<pre class="language-"><code>$ kubectl get deployment  nginx-deploymentNAME               READY   UP-TO-DATE   AVAILABLE   AGEnginx-deployment   2/2     2            2           43s$ kubectl get rs nginx-deployment-69b6b4c5cdNAME                          DESIRED   CURRENT   READY   AGEnginx-deployment-69b6b4c5cd   2         2         2       57s$ kubectl get podNAME                                READY   STATUS    RESTARTS   AGEnginx-deployment-69b6b4c5cd-26dsn   1/1     Running   0          66snginx-deployment-69b6b4c5cd-6rqqc   1/1     Running   0          64s$ kubectl edit rs nginx-deployment-69b6b4c5cd   // deployment &#x5173;&#x8054;&#x7684; rs &#x5BF9;&#x8C61;  apiVersion: apps/v1kind: ReplicaSetmetadata:  name: nginx-deployment-69b6b4c5cd  namespace: default  ownerReferences:  - apiVersion: apps/v1    blockOwnerDeletion: true    controller: true    kind: Deployment    name: nginx-deployment    uid: 40a1044e-03d1-48bc-8806-cb79d781c946  finalizers:  - foregroundDeletion       // &#x4E3A; rs &#x624B;&#x52A8;&#x6DFB;&#x52A0;&#x7684; Foreground &#x7B56;&#x7565;  ......spec:  replicas: 2  ......status:  ......
</code></pre><p>&#x5F53; deployment&#x3001;rs&#x3001;pod &#x90FD;&#x5904;&#x4E8E;&#x6B63;&#x5E38;&#x8FD0;&#x884C;&#x72B6;&#x6001;&#x4E14; deployment &#x5173;&#x8054;&#x7684; rs &#x4F7F;&#x7528; <code>Foreground</code> &#x5220;&#x9664;&#x7B56;&#x7565;&#x65F6;&#xFF0C;&#x7136;&#x540E;&#x9A8C;&#x8BC1;&#x6E90;&#x7801;&#x4E2D;&#x63D0;&#x5230;&#x7684;&#x4E09;&#x79CD;&#x65B9;&#x6CD5;&#xFF0C;&#x9A8C;&#x8BC1;&#x65F6;&#x9700;&#x8981;&#x6A21;&#x62DF;&#x4E00;&#x4E2A;&#x4F9D;&#x8D56;&#x5BF9;&#x8C61;&#x65E0;&#x6CD5;&#x5220;&#x9664;&#x7684;&#x573A;&#x666F;&#xFF0C;&#x5F53;&#x7136;&#x8FD9;&#x4E2A;&#x4E5F;&#x5F88;&#x597D;&#x6A21;&#x62DF;&#xFF0C;&#x4E09;&#x79CD;&#x573A;&#x666F;&#x5982;&#x4E0B;&#x6240;&#x793A;&#xFF1A;</p>
<ul>
<li>1&#x3001;&#x5F53; pod &#x6240;&#x5728;&#x7684; node &#x5904;&#x4E8E; Ready &#x72B6;&#x6001;&#x65F6;&#xFF0C;&#x4EE5; <code>Foreground</code> &#x7B56;&#x7565;&#x5220;&#x9664; deploment&#xFF0C;&#x56E0;&#x4E3A; rs &#x5173;&#x8054;&#x7684; pod &#x4F1A;&#x76F4;&#x63A5;&#x88AB;&#x5220;&#x9664;&#xFF0C;rs &#x4E5F;&#x4F1A;&#x88AB;&#x6B63;&#x5E38;&#x5220;&#x9664;&#xFF0C;&#x6B64;&#x65F6; deployment &#x4E5F;&#x4F1A;&#x76F4;&#x63A5;&#x88AB;&#x5220;&#x9664;&#xFF1B;</li>
<li>2&#x3001;&#x5F53; pod &#x6240;&#x5728;&#x7684; node &#x5904;&#x4E8E; NotReady &#x72B6;&#x6001;&#x65F6;&#xFF0C;&#x4EE5; <code>Foreground</code> &#x7B56;&#x7565;&#x5220;&#x9664; deploment&#xFF0C;&#x6B64;&#x65F6;&#x56E0; rs &#x5173;&#x8054;&#x7684; pod &#x65E0;&#x6CD5;&#x88AB;&#x5220;&#x9664;&#xFF0C;rs &#x4F1A;&#x4E00;&#x76F4;&#x5904;&#x4E8E;&#x5220;&#x9664;&#x963B;&#x585E;&#x72B6;&#x6001;&#xFF0C;deployment &#x7531;&#x4E8E; rs &#x65E0;&#x6CD5;&#x88AB;&#x5220;&#x9664;&#x4E5F;&#x4F1A;&#x5904;&#x4E8E;&#x5220;&#x9664;&#x963B;&#x585E;&#x72B6;&#x6001;&#xFF0C;&#x6B64;&#x65F6;&#x66F4;&#x65B0; rs &#x53BB;&#x6389;&#x5176; <code>ownerReferences</code> &#x4E2D;&#x5BF9;&#x5E94;&#x7684; deployment &#x90E8;&#x5206;&#xFF0C;deployment &#x4F1A;&#x56E0;&#x65E0;&#x4F9D;&#x8D56;&#x5BF9;&#x8C61;&#x88AB;&#x6210;&#x529F;&#x5220;&#x9664;&#xFF1B;</li>
<li>3&#x3001;&#x548C; 2 &#x540C;&#x6837;&#x7684;&#x573A;&#x666F;&#xFF0C;node &#x5904;&#x4E8E; NotReady &#x72B6;&#x6001;&#x65F6;&#xFF0C;&#x4EE5; <code>Foreground</code> &#x7B56;&#x7565;&#x5220;&#x9664; deploment&#xFF0C;deployment &#x548C; rs &#x5C06;&#x5904;&#x4E8E;&#x5220;&#x9664;&#x963B;&#x585E;&#x72B6;&#x6001;&#xFF0C;&#x6B64;&#x65F6;&#x5C06; rs <code>ownerReferences</code> &#x4E2D;&#x5173;&#x8054; deployment &#x7684; <code>blockOwnerDeletion</code> &#x5B57;&#x6BB5;&#x8BBE;&#x7F6E;&#x4E3A; false&#xFF0C;&#x53EF;&#x4EE5;&#x770B;&#x5230; deployment &#x4F1A;&#x56E0;&#x65E0; block &#x4F9D;&#x8D56;&#x5BF9;&#x8C61;&#x88AB;&#x6210;&#x529F;&#x5220;&#x9664;&#xFF1B;</li>
</ul>
<pre class="language-"><code>$ systemctl stop kubelet
// node &#x5904;&#x4E8E; NotReady &#x72B6;&#x6001;
$ kubectl get node
NAME       STATUS     ROLES    AGE     VERSION
minikube   NotReady   master   6d11h   v1.16.2
// &#x4EE5; Foreground &#x7B56;&#x7565;&#x5220;&#x9664; deployment
$ curl -k -v -XDELETE  -H &quot;Accept: application/json&quot;-H &quot;Content-Type: application/json&quot;-d &apos;{&quot;propagationPolicy&quot;:&quot;Foreground&quot;}&apos;&apos;https://192.168.99.108:8443/apis/apps/v1/namespaces/default/deployments/nginx-deployment&apos;
</code></pre><h3 id="&#x603B;&#x7ED3;"><a name="&#x603B;&#x7ED3;" class="anchor-navigation-ex-anchor" href="#&#x603B;&#x7ED3;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x603B;&#x7ED3;</h3>
<p>GarbageCollectorController &#x662F;&#x4E00;&#x79CD;&#x5178;&#x578B;&#x7684;&#x751F;&#x4EA7;&#x8005;&#x6D88;&#x8D39;&#x8005;&#x6A21;&#x578B;&#xFF0C;&#x6240;&#x6709; <code>deletableResources</code> &#x7684; informer &#x90FD;&#x662F;&#x751F;&#x4EA7;&#x8005;&#xFF0C;&#x6BCF;&#x79CD;&#x8D44;&#x6E90;&#x7684; informer &#x76D1;&#x542C;&#x5230;&#x53D8;&#x5316;&#x540E;&#x90FD;&#x4F1A;&#x5C06;&#x5BF9;&#x5E94;&#x7684;&#x4E8B;&#x4EF6; push &#x5230; graphChanges &#x4E2D;&#xFF0C;graphChanges &#x662F; GraphBuilder &#x5BF9;&#x8C61;&#x4E2D;&#x7684;&#x4E00;&#x4E2A;&#x6570;&#x636E;&#x7ED3;&#x6784;&#xFF0C;GraphBuilder &#x4F1A;&#x542F;&#x52A8;&#x53E6;&#x5916;&#x7684; goroutine &#x5BF9; graphChanges &#x4E2D;&#x7684;&#x4E8B;&#x4EF6;&#x8FDB;&#x884C;&#x5206;&#x7C7B;&#x5E76;&#x653E;&#x5728;&#x5176; attemptToDelete &#x548C; attemptToOrphan &#x4E24;&#x4E2A;&#x961F;&#x5217;&#x4E2D;&#xFF0C;garbageCollector &#x4F1A;&#x542F;&#x52A8;&#x591A;&#x4E2A; goroutine &#x5BF9; attemptToDelete &#x548C; attemptToOrphan &#x4E24;&#x4E2A;&#x961F;&#x5217;&#x4E2D;&#x7684;&#x4E8B;&#x4EF6;&#x8FDB;&#x884C;&#x5904;&#x7406;&#xFF0C;&#x5904;&#x7406;&#x7684;&#x7ED3;&#x679C;&#x5C31;&#x662F;&#x56DE;&#x6536;&#x4E00;&#x4E9B;&#x9700;&#x8981;&#x88AB;&#x5220;&#x9664;&#x7684;&#x5BF9;&#x8C61;&#x3002;&#x6700;&#x540E;&#xFF0C;&#x518D;&#x7528;&#x4E00;&#x4E2A;&#x6D41;&#x7A0B;&#x56FE;&#x603B;&#x7ED3;&#x4E00;&#x4E0B; GarbageCollectorController &#x7684;&#x4E3B;&#x8981;&#x6D41;&#x7A0B;:</p>
<pre class="language-"><code>                      monitors (producer)
|
|
&#x2228;
                    graphChanges queue
|
|
&#x2228;
                    processGraphChanges
|
|
&#x2228;
-------------------------------
||
||
&#x2228;&#x2228;
  attemptToDelete queue         attemptToOrphan queue
||
||
&#x2228;&#x2228;
AttemptToDeleteWorkerAttemptToOrphanWorker
(consumer)(consumer)
</code></pre><footer class="page-footer"><span class="copyright">Copyright &#xA9; caixisheng 2017 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x8BE5;&#x6587;&#x4EF6;&#x4FEE;&#x8BA2;&#x65F6;&#x95F4;&#xFF1A;
2021-05-30 15:16:15
</span></footer> <link rel="stylesheet" type="text/css" href="https://storage.googleapis.com/app.klipse.tech/css/codemirror.css"> <script>     window.klipse_settings = {         selector: ".language-klipse, .lang-eval-clojure",         selector_eval_js: ".lang-eval-js",         selector_eval_python_client: ".lang-eval-python",         selector_eval_php: ".lang-eval-php",         selector_eval_scheme: ".lang-eval-scheme",         selector_eval_ruby: ".lang-eval-ruby",         selector_reagent: ".lang-reagent",        selector_google_charts: ".lang-google-chart",        selector_es2017: ".lang-eval-es2017",        selector_jsx: ".lang-eval-jsx",        selector_transpile_jsx: ".lang-transpile-jsx",        selector_render_jsx: ".lang-render-jsx",        selector_react: ".lang-react",        selector_eval_markdown: ".lang-render-markdown",        selector_eval_lambdaway: ".lang-render-lambdaway",        selector_eval_cpp: ".lang-eval-cpp",        selector_eval_html: ".lang-render-html",        selector_sql: ".lang-eval-sql",        selector_brainfuck: "lang-eval-brainfuck",        selector_js: ".lang-transpile-cljs"    }; </script> <script src="https://storage.googleapis.com/app.klipse.tech/plugin/js/klipse_plugin.js"></script>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="calico 源码分析.html" class="navigation navigation-prev " aria-label="Previous page: Calico 源码分析">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="job.html" class="navigation navigation-next " aria-label="Next page: Job">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Garbage Collector Controller 源码分析","level":"1.9.4.2","depth":3,"next":{"title":"Job","level":"1.9.4.3","depth":3,"path":"blog/kubernetes/K8s源码/job.md","ref":"blog/kubernetes/K8s源码/job.md","articles":[]},"previous":{"title":"Calico 源码分析","level":"1.9.4.1","depth":3,"path":"blog/kubernetes/K8s源码/calico 源码分析.md","ref":"blog/kubernetes/K8s源码/calico 源码分析.md","articles":[]},"dir":"ltr"},"config":{"plugins":["summary","expandable-chapters","toggle-chapters","theme-comscore","-lunr","-search","-highlight","-livereload","search-plus@^0.0.11","simple-page-toc@^0.1.1","github@^2.0.0","github-buttons@2.1.0","edit-link@^2.0.2","disqus@^0.1.0","prism@^2.1.0","prism-themes@^0.0.2","advanced-emoji@^0.2.1","anchors@^0.7.1","include-codeblock@^3.0.2","emphasize@^1.1.0","katex@^1.1.3","splitter@^0.0.8","mermaid-gb3@2.1.0","tbfed-pagefooter@^0.0.1","expandable-chapters-small@^0.1.7","sectionx@^3.1.0","donate@^1.0.2","local-video@^1.0.1","anchor-navigation-ex@0.1.8","favicon@^0.0.2","3-ba@^0.9.0","terminal@^0.3.2","alerts@^0.2.0","include-csv@^0.1.0","puml@^1.0.1","musicxml@^1.0.2","klipse@^1.2.0","versions-select@^0.1.1","-sharing","sharing-plus@^0.0.2","graph@^0.1.0","chart@^0.2.0"],"root":".","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright © caixisheng 2017","modify_label":"该文件修订时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"prism":{"css":["prism-themes/themes/prism-base16-ateliersulphurpool.light.css"]},"include-csv":{},"disqus":{"useIdentifier":false,"shortName":"gitbookuse"},"emphasize":{},"github":{"url":"https://github.com/xishengcai/xisheng.blog"},"puml":{},"simple-page-toc":{"maxDepth":3,"skipFirstH1":true},"summary":{},"splitter":{},"sharing-plus":{"qq":false,"all":["facebook","google","twitter","instapaper","linkedin","pocket","stumbleupon"],"douban":false,"facebook":true,"weibo":false,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":true,"messenger":false,"line":false,"vk":false,"pocket":true,"google":false,"viber":false,"stumbleupon":false,"qzone":false,"linkedin":false},"versions-select":{"type":"branches"},"graph":{},"donate":{"alipay":"https://cai-hello-1253732611.cos.ap-shanghai.myqcloud.com/share/zhifubao-pay.jpg","alipayText":"支付宝打赏","button":"赏","title":"","wechat":"https://cai-hello-1253732611.cos.ap-shanghai.myqcloud.com/share/weixin-pay.jpg","wechatText":"微信打赏"},"katex":{},"fontsettings":{"theme":"white","family":"sans","size":2},"musicxml":{},"sectionx":{"tag":"b"},"mermaid-gb3":{},"anchor-navigation-ex":{"isRewritePageTitle":false,"tocLevel1Icon":"fa fa-hand-o-right","tocLevel2Icon":"fa fa-hand-o-right","tocLevel3Icon":"fa fa-hand-o-right"},"favicon":{"shortcut":"favicon.ico","bookmark":"favicon.ico"},"theme-comscore":{},"prism-themes":{},"alerts":{},"github-buttons":{"repo":"xishengcai/xisheng.blog","types":["star"],"size":"small"},"3-ba":{"configuration":"auto","token":"ff100361cdce95dd4c8fb96b4009f7bc"},"expandable-chapters-small":{},"local-video":{},"klipse":{"myConfigKey":"it's the default value"},"advanced-emoji":{"embedEmojis":false},"include-codeblock":{"check":false,"edit":true,"fixlang":false,"lang":"","template":"ace","theme":"chrome","unindent":true},"sharing":{"qq":false,"all":["facebook","google","twitter","weibo","instapaper","linkedin","pocket","stumbleupon","qq","qzone"],"douban":false,"facebook":false,"weibo":true,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":false,"messenger":false,"line":false,"vk":false,"pocket":false,"google":true,"viber":false,"stumbleupon":false,"qzone":false,"linkedin":true},"terminal":{"copyButtons":true,"fade":false,"style":"flat"},"edit-link":{"label":"Edit This Page","base":"https://github.com/xishengcai/xisheng.blog/edit/master"},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":true},"anchors":{},"chart":{"type":"c3"},"toggle-chapters":{},"expandable-chapters":{},"search-plus":{}},"theme":"default","author":"xishengcai","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"这是程序员吗","language":"zh-hans","output.name":"site","links":{"sidebar":{"Home":"https://xisheng.vip"}},"gitbook":"3.2.3","description":"这是程序员吗"},"file":{"path":"blog/kubernetes/K8s源码/garbage collector controller 源码分析.md","mtime":"2021-05-30T07:16:15.630Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-06-23T07:51:54.455Z"},"basePath":"../../..","book":{"language":""}});
        });
    </script>
</div>

        
    
    <script src="../../../gitbook/gitbook.js"></script>
    <script src="../../../gitbook/theme.js"></script>
    
        
        <script src="../../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-toggle-chapters/toggle.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-search-plus/jquery.mark.min.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-search-plus/search.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-github/plugin.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-github-buttons/plugin.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-edit-link/plugin.js"></script>
        
    
        
        <script src="https://cdnjs.cloudflare.com/ajax/libs/URI.js/1.16.1/URI.min.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-disqus/plugin.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-mermaid-gb3/book/plugin.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.js"></script>
        
    
        
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-sectionx/sectionx.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-donate/plugin.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-local-video/video.min.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-3-ba/plugin.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-terminal/plugin.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-alerts/plugin.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-musicxml/osmd.min.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-musicxml/musicxml.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-musicxml/promise.min.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-versions-select/plugin.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-sharing-plus/buttons.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-theme-comscore/test.js"></script>
        
    

    <script src="../../../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.min.js"></script>

    </body>
</html>

